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