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