in reply to newbie to regex: all matches

Others have alluded to the issues and better ways for handling html data, but then again, your particular task looks pretty basic, and anyway the real question is "how to use a regex match in such a way that we handle every instance of a pattern in a given string?"

The basic answer to that is the "g" modifier, placed at the end of the regex. Some examples:

$_ = <<ETX; Long text string foo_1... with multiple foo_2 lines... and who cares foo_3 what else... ETX while ( /foo_\d+(.*)/g ) { # loop over every match print "found '$1' between foo and end-of-line\n"; } s/foo_/bar=/g; # replace all occurrences of foo with bar my @bars = ( /(bar=\d+)/g ); # capture all occurrences to an array print "@bars\n";