while ($str =~ m{$your_regex}g) { my ($x, $y) = ($1, $2); # This loop will repeat for as many matches as are in $str }