in reply to Can't understand why /g does not work as I expect

The issue is not so much any obvious misunderstanding of m//g as failure to consider greediness. Read about that, using perldoc perlretut or your own choice of reference, and note the limit on greed (in the form of a "?" after each "*" in the code below.

#!/usr/bin/perl use strict; use warnings; #829607 =head The idea was to get two lines like: foo, <anystring 1 /> bar, <anystring 2 /> =cut my $string = "<name=\"foo\"><anystring 1 /></name><name=\"bar\"><anyst +ring 2 /></name>"; while ($string =~ m/<name=\"(.*?)\">(.*?)<\/name>/g) { print "$1, $2\n"; }

Output:

ww@GIG:~/pl_test$ perl 829607.pl foo, <anystring 1 /> bar, <anystring 2 /> ww@GIG:~/pl_test$