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.
|
|---|