# 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 }