my @runs; my $pos = 0; my $b = $a; my $c = lc substr $b, 0, 1, ''; my $next; while ( $b ) { my $start = $pos; 1 while ++$pos and ( $next = lc substr $b, 0, 1, '' ) eq $c; for my $i ( $start .. $pos - $n ) { push @runs, substr $a, $i, $n; } $c = $next; }