http://www.perlmonks.org?node_id=432534


in reply to counting overlapping patterns

There's also the simple:

while ("AAAA" =~ /A(A+)/g) { $count += length($1); }

Unlike C's strlen, Perl's length doesn't loop, so this snippet is compliant with your request for no further looping.