If you are counting characters, you can use tr//. If you are matching strings, you can use s//. Both return the number of substitutions made:
$count = ($line =~ tr/X/X/); $count = ($line =~ s/(match1|match2)/$1/g);
Just make sure you reset the position with the pos function if you are using a string (vs a single character) and you want to find overlapping matches.
HTHIn reply to Re: number of matches
by bobf
in thread number of matches
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |