in reply to Replace all characters inbetween

Using a simple substitution with look behind and look ahead seems to fit the bill:

use strict; use warnings; my $str = 'XAXAAAAXXXXXXXAAXXXXXAXXXXAAAAX'; my $before = $str; $str =~ s/(?<=A)(X+)(?=A)/'a' x length $1/ge; print "$before\n"; print "$str\n";

Prints:

XAXAAAAXXXXXXXAAXXXXXAXXXXAAAAX XAaAAAAaaaaaaaAAaaaaaAaaaaAAAAX

with lower case 'a' used to make the substitutions clear.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond