@count=$string=~m/apple/g; ... , scalar @count, ...
You can get the count directly using this construct.
$ perl -E ' > $str = q{I like apples, pears and pineapples}; > $count = () = $str =~ m{apple}g; > say $count;' 2 $
I hope this is of interest.
Cheers,
JohnGG
In reply to Re^2: all occurences of a target word by regular expression
by johngg
in thread all occurences of a target word by regular expression
by siskos1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |