in reply to another tricky one from lol

I'm not sure exactly what your doing, but could you just use substr? I wrote a small sample below that outputs "pre XXXXXXX post"
$string = "pre replace post"; $i = 4; $j = 11; $length = $j - $i; $result = substr($string,0,$i) . "x" x $length . substr($string,$j); print "$result\n";

Replies are listed 'Best First'.
Re: another tricky one from lol
by sfink (Deacon) on Apr 19, 2002 at 20:41 UTC
    substr is lvaluable:
    $string = "pre replace post"; $i = 4; $j = 11; $length = $j - $i; substr($string, $i, $length) = "x" x $length; print "$string\n";
    Or to avoid using $length twice:
    $string = "pre replace post"; $i = 4; $j = 11; substr($string, $i, $j - $i) =~ tr/x/x/c; print "$string\n";
    But that's probably gratuitous obfuscation.