perlfaq nodetype
faq_monk
<P>
Most people mean that greedy regexps match as much as they can. Technically
speaking, it's actually the quantifiers (<CODE>?</CODE>, <CODE>*</CODE>, <CODE>+</CODE>,
<CODE>{}</CODE>) that are greedy rather than the whole pattern; Perl prefers local greed
and immediate gratification to overall greed. To get non-greedy versions of
the same quantifiers, use (<CODE>??</CODE>, <CODE>*?</CODE>, <CODE>+?</CODE>, <CODE>{}?</CODE>).
<P>
An example:
<P>
<PRE> $s1 = $s2 = "I am very very cold";
$s1 =~ s/ve.*y //; # I am cold
$s2 =~ s/ve.*?y //; # I am very cold
</PRE>
<P>
Notice how the second substitution stopped matching as soon as it
encountered ``y ''. The <CODE>*?</CODE> quantifier effectively tells the regular expression engine to find a match
as quickly as possible and pass control on to whatever is next in line,
like you would if you were playing hot potato.
<P>