# In a world without regular expressions, # it's just a simple matter of programming: my $count = 0; my $pos = 0; while( $pos != length $string ) { $count++ if 'aa' eq substr $string, $pos++, 2 } #### # Using 'pos()': while( $string =~ /aa/g ) { pos($string) = pos($string) - 1; $count++ } #### $count++ while $string =~ /a(?=a)/g; # Using a lookahead assertion. #### my $c = () = $string =~ m/(?=aa)/g; say $c;