my $re = qr/ First\ Name: \s+ (.+)\n Last\ Name: \s+ (.+)\n (?:.+\n)* Location:\ Central\ USA\n /x; while ($line=~/$re/g) { print "<$1> <$2>\n"; }