http://www.perlmonks.org?node_id=671623


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

Remember you can also use perl to edit files in-place.
> perl -p -i.bak -e "s/(.*)/$1\n****************/" test.txt
The above command will append a new line containing **************** after every line in the document.

Now I have a question for the more experienced Perlers, can I do in-place file substitution from inside a script using just Perl code. Or do I have to execute as a command line? I know I can execute a command line within a Perl script, but what I mean, can I do it otherwise, without going to the command line in any way?