in reply to Is there an elegant way of resetting the match position?

Maybe you could generate all 'pairs' (which scales nicely to N) then filter them:

use strict; use warnings; my $str = 'aaAabBAAa'; my $N = 2; print join "\n", grep {/^(.)\1+$/i} map {substr $str, $_, $N} 0 .. length ($str) - $N;

Prints:

aa aA Aa bB AA Aa

Update: Changed to match N adjacent characters.


True laziness is hard work