A dot '.' character unescaped matches exactly one of any character (except newline by default). .* means match any character zero or more times but as many times as possible (it'll eat up the entire string up to the first newline). This is greedy. Essentially, greedy means match as much as absolutely possible while allowing the rest of the regex to still match.
To make something non-greedy, use a ? after the .*. It will then match as much as it can, as few times as possible.
my $str = "hello there world";
The following captures 'world', as the first .* grabs any char up to a space. Because it's greedy, it doesn't stop until the last space, and the rest (the second .*) is captured.
$str =~ /.*\s(.*)/;
The regex below captures 'there world'. The non-greedy modifier after the first .* says any char up to a space, but stop at the first opportunity you can (the first space). The (.*) captures everything else.
$str =~ /.*?\s(.*)/;
See perlretut for much more information.
-stevieb |