I also don't see why you need to replace each newline with replace, and then later on do the reverse substitution.
It seems to me your whole script could be replaced by
$ perl -i -pe 's/the line to be replaced/this is the new line/' var.tx +t
In reply to Re: A Better Way
by moritz
in thread A Better Way
by toniax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |