in reply to Getting the number of times a regexp matches
Everyone so far seems to have missed this bit of evil context bashing:
$num_matches = () = $string =~ m/pattern/g;This works because the () force the far right hand side to be evaluated in list context, the result of which is then reevaluated in scalar context to give the result. This is a nice example using side effects to good cause in perl.
In Section
Seekers of Perl Wisdom