Suppose I have:
my $string = \"one.two.three.four\";
How should I play with context to get the number of times the pattern found a match (3
Friedo's method is: $a = () = $b =~ $c.
But it's possible to simplify this even further to just ($a) = $b =~ $c, like so :
my ($matchcount) = $text =~ s/$findregex/ /gi;
You could thank just wrap this up in a function, getMatchCount(), and not worry about it destroying the passed string.
On the other hand, you can add in a swap, which may be a bit more computation, but does not result in altering the string.
my ($matchcount) = $text =~ s/($findregex)/$1/gi;