 <p>The problem is that you're not escaping the special characters in the text, such as the <code>/</code> delimiter.</p> <p>The easiest solution is to pick a different delimiter and to specify only a part of the string, for instance</p> <pre><code>find . -name '*.html' -o -name '*.htm' | xargs fgrep -l '&lt;script&gt;i=0;try' | xargs perl -i.infected -pe 's#&lt;script&gt;i=0;try.*?&lt;/script&gt;##g' </code></pre> <p>(untested) may do the job. (The <code>.*?</code> construct picks the shortest match; I don't know how to do that in <code>sed</code>.)</p> <p>Verify with something like</p> <pre><code>find . -name '*.infected' | sed -e 's#.*#diff &amp; &amp;#' -e 's#.infected##' | sh -x </code></pre>