use 5.010; $/ = "\n--\n"; while ( defined(my $line = <$fh>) ){ say $1 if $line =~ /\b0x014E\b/ and $line =~ /^(Output: .+)/m; }