my( $header, $time, $error, $status ); while (<>) { /my_header (.*)/ and $header = $1; /time: (.*)/ and $time = $1; /error: (.*)/ and $error = $1; /status: (.*)/ and $status = $1; } $header && $time && $status or die "Error: missing one or more of header, time, status\n";