in reply to Backreferences in negated character classes

Didn't notice the interesting bit :). Extended to handle AABCCCCAD:

use strict; use warnings; my $string = 'WXYYZAABCCCCADWWXYYYZAAbCCCCAd'; print $1, "\n" while $string =~ m/( ([\w])(?=\2).(?!\2)(.) # Match AAB (?!\2|\3)(.) # C \4{3} # CCC \2 # A (?!\2|\3|\4). # D )/xg;

Prints:

AABCCCCAD AAbCCCCAd

DWIM is Perl's answer to Gödel