in reply to A query on greedy regexps

For a good start on greedy regexps see Ovid's classic Death to Dot Star!. Essentially the greediness of a regexp relates to the fact that both * and + will match the preceding atom for as long as possible. However you can alter this behaviour by appending either modifier with a question mark e.g
my $str = "123 foo 456 foo 789 foo 10"; # will match everything up to the last 'foo' print "dot star greedy: ", $str =~ /(.*)foo/, $/; # will match everything up to the first 'foo' print "dot star non-greedy: ", $str =~ /(.*?)foo/, $/; __output__ dot star greedy: 123 foo 456 foo 789 dot star non-greedy: 123

HTH

_________
broquaint

update: made code more illustrative