in reply to Re: read from a file and write into the same file
in thread read from a file and write into the same file

You can do inplace editing from inside scripts with $^I, which is the equivalent for the -i command line option. It is described in perlvar.