use strict; use warnings; my $string = "aabbzzb"; my $oldchars = "ab"; my $newchars = "xx"; $_ = $string; #replace the chars by "x" char. eval "tr/$oldchars/$newchars/, 1" or die $@; $string = $_; #then delete the 'x' char. $string =~ tr/x//d; print $string; #will print zz