Code tags are your (and our) friends.
Your problem is that you don't store the number of matches. The following code will fix your issue.
use warnings; use strict; my $cnt = 0; my $str = "hi hi harshmane hi hi"; $cnt = ($str =~ s/(harsh)/$1/g); print "'harsh' appears $cnt times.\n"; $cnt = ($str =~ s/(hi)/$1/g); print "'hi' appears $cnt times.\n"; #OUTPUT #'harsh' appears 1 times. #'hi' appears 4 times.
In reply to Re: how to find substring using regex
by zek152
in thread how to find substring using regex
by harshmane
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |