You can use the -i perl flag to change the file "in place" (see perlrun). You have to print all the lines, though, not only the changed one, and process the input with the diamond operator <> instead of creating your own file handle.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Comment on Re: How do I modify a line within the file itself?