in reply to Count number of occurrences of a substr

This is a FAQ (see perlfaq4):
perldoc -q count
use warnings; use strict; my $str = "thisthis"; if ( my $n = () = ($str =~ m/this/g) ) { print qq{Found $n occurrence(s) of "this"\n}; } __END__ Found 2 occurrence(s) of "this"
Perl Idioms Explained - my $count = () = /.../g