in reply to Removing a chunk of HTML?

You're not writing out the data.  Doing the substitution on $string that you read from the file won't modify the file (even when opened with "+<"), just the string.

Unless you have a backup of the files elsewhere, it's probably safest to write the modified content ($string) to another file, and only delete the original one when there weren't any errors.

(P.S.: you're loading File::Slurp but don't seem to be using it...   Also, if you really had use strict in your code, it would complain 'Global symbol "..." requires explicit package name...' for $i and $string)