my $regex = quotemeta q{document.write(this.location.href.replace(/\?resultof.*$/i, ''));}; my $j =~ s/$regex/something else/;