in reply to String replace, another question

See How (Not) To Ask A Question. Your question is very unclear. For example what do you mean "run it from within the file"? What's in $line?

If $line indeed contains just a single line as the variable name suggests, the regex will never match, because it requires multiple lines in the same string.