- or download this
my $a = "17341234173412341734123417341234";
$a=~s/(.)(?=...\1)/A/g;
$a=~s/(?<=A...)(.)/B/g;
print $a;
A7AAB2BBB7BBB2BBB7BBB2BBB7BBB2BB
- or download this
my $a = "17341234173412341734123417341234";
my $n=0;
$n++ while $a =~ s/(.)(...)\1/A$2B/;
print $n, $a;
12 A7AAB2BBA7AAB2BBA7AAB2BBA7AAB2BB
- or download this
my $a = "17341234173412341734123417341234";
substr($a, $_, 5) =~ s[(.)(...)\1][A$2B] for 0 .. length ($a);
print $a;
A7AAB2BBA7AAB2BBA7AAB2BBA7AAB2BB