my $line = 'abbc'; $line =~ s/(.)\1/XX/g; say $line; --output:-- aXXc