darisler,
If you use a regex with the global modifier in scalar context, you will get an iterator allowing you to go through each set of matches one at a time (like one of the examples above):
while ($str =~ m{$your_regex}g) {
my ($x, $y) = ($1, $2);
# This loop will repeat for as many matches as are in $str
}