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

try this

lanx@nc10-ubuntu:~$ perl -de0 ... DB<1> $a="aaAabBAAa"; DB<2> print join " ",($a =~ /((.)\G\2|(.)\3)/gi) aa a aA a Aa A bB b AA A Aa A

there should be a way to backreference matches without listing them afterwards, but I have no time to look it up.

otherwise:

DB<3> print $&," " while ($a =~ /(.)\G\1|(.)\2/gi) aa aA Aa bB AA Aa

Hope it helps!

Cheers Rolf