# Using 'pos()': while( $string =~ /aa/g ) { pos($string) = pos($string) - 1; $count++ }