my $string = 'aaaabcccc'; $string =~ s/(?<=a+)b(?=c+)/B/; say $string; # Variable length lookbehind not implemented in regex m/(?<=a+)b(?=c+)/ at C:\Projects\test.pl line 15.