in reply to Replace all characters inbetween

> So, this string:

> AAAAAXXXXXXXAAAXXXXXAXXXXAAAA

> becomes:

> AAAAAAAAAAAAAAAAAAAAAAAAAAAAA

replacing "X" -> "a" for better demo

use v5.12.0; use warnings; my $in = 'AAAAAXXXXXXXAAAXXXXXAXXXXAAAA'; my $out = $in =~ s [ (?<=A) X+ (?=A) ] [ $& =~ tr/X/a/r ]gexr; say $in; say $out;

AAAAAXXXXXXXAAAXXXXXAXXXXAAAA AAAAAaaaaaaaAAAaaaaaAaaaaAAAA

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

simplified $1 to $&