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