$_ = "abffdeabggfrabhhjuab"; my $matches =()= m/ab/g; print $matches; # 4
See Perl Idioms Explained - my $count = () = /.../g for an explanation of =()=, the operator-that-shall-not-be-named :)
Update: Removed superfluous brackets from regexp & added a linky
In reply to Re: counting matches in a line
by FunkyMonk
in thread counting matches in a line
by halfcountplus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |