Using Raku (formerly known as Perl_6)
~$ raku -ne 'say "$_\t", ($/.elems given .match: :overlap, /aa/);' file
#OR:
~$ raku -ne 'say "$_\t", .match(:overlap, /aa/).elems;' file
OR:
~$ raku -ne 'say "$_\t", ($/.elems given m:overlap/aa/);' file
#OR:
~$ raku -ne 'say "$_\t", m:overlap/aa/.elems;' file
Above is an answer written in Raku, a member of the Perl-family of programming languages. Among other things, Raku features high-level support for Unicode, including accurate Unicode character matching and/or counting. Above, all four code variants make use of Raku's :overlap regex modifier ("adverb" in Raku lingo, i.e. named argument).
Sample Input:
x
a
aa
aaa
aaaa
aa aaa aaaa
Sample Output:
x 0
0
a 0
aa 1
aaa 2
aaaa 3
aa aaa aaaa 6
If you need a file sum (as opposed to a linewise sum), you can use BEGIN/END blocks like with awk:
~$ raku -ne 'BEGIN my $n = 0; $n += .match(:overlap, /aa/).elems; END say $n;' file
12
I mentioned Unicode support so here's a quick example (and see first link below):
~$ printf '«AAÁÁÅÅÀÀÄÄBBßßœœþþ» CDE\n' | raku -ne 'say "Input string \"$_\" contains " ~ .match(:overlap,/AA/).elems ~ " overlapping AA match(es).";'
Input string "«AAÁÁÅÅÀÀÄÄBBßßœœþþ» CDE" contains 1 overlapping AA match(es).
https://unix.stackexchange.com/a/767221/227738
https://docs.raku.org/language/regexes#Overlap
https://raku.org