in reply to Replace zero-width grouping?

Update: Enlil points out that this suffers from the same problem as the OP's own solution, highlighted by BrowserUk.
#!/usr/bin/perl -wl use strict; $_="17341234"; s/(.)(?=...\1)|(?<=(.)...)\2/defined $1 ? "A" : "B"/eg; print; __END__ A7AAB2BB

Makeshifts last the longest.