#!perl use strict; use warnings; use feature qw( say ); my $string = 'aaaabcccc'; $string =~ s/a+\Kb(?=c+)/B/; say $string; __END__ aaaaBcccc