<1f7de2a9-fd67-4db1-b6d3-1da850c956c2@glegroupsg2000goo.googlegroups.com>
Perl regular expressions normally match the longest string possible, but this
example prints "a|a". Why does it match?
<<snip>>
"aax" =~ m/(^a*)([^x])/;
print "$1|$2\n" ;
Perl will _start_ with the longest possible match for 'a*' in your
regular expression (because a non-qualified '*' is "greedy"), but if it
fails to match because of what follows, then it will shorten the
sub-match by one character and try again. Since the next character
after the first-matched 'aa' is 'x', and you have specified that the
next character be anything but 'x' ([^x]), the match with 'aa' fails.
Perl tries again with 'a', and since the next 'a' matches [^x], the
match succeeds and "a|a" is printed.