in reply to counting overlapping patterns

Why not let Perl do the incrementing itself?

$count = () = "AAAA" =~ m/(?=AA)/g;