$string = "pre replace post"; $i = 4; $j = 11; substr($string, $i, $j - $i) =~ tr/x/x/c; print "$string\n";