my $re = qr/]* # an anchor tag href= # the Href in the anchor (["'])((?:(?!\1).)*)\1 # the value in the href [^>]*> # anything to the end of the anchor [^<>]* # the content in the anchor tag <\/a> # the end of the anchor (?:\s|<[^>]*>)+ # any whitespace or html tags (\d{9}) # the 9 digit number /isxm; my $string = do{local $/; }; while($string =~ m/$re/g){ my $href = $2; my $number = $3; print "$number - $href\n"; } __DATA__

A

Abbott, Evelyn
110136892
Agnew, Thomas
110377660
Allison, David
108116112
Allison, Gary Owen
116815754
Arsenault, Michael
108318866
Arsenault, Normand A.
113069066