sub replace { my ($str,$find,$repl,$pos)=@_; $pos||=0; while ((my $index=index($str,$find,$pos))>=0) { substr($str,$index,length($find))=$repl; $pos+=length($repl); } return $str; }