Help for this page

Select Code to Download


  1. 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
    }
    
  2. or download this
    # Using 'pos()':
    while( $string =~ /aa/g ) {
        pos($string) = pos($string) - 1;
        $count++ 
    }
    
  3. or download this
    $count++ while $string =~ /a(?=a)/g; # Using a lookahead assertion.
    
  4. or download this
    my $c = () = $string =~ m/(?=aa)/g;
    say $c;