in reply to printing and logging to a file

Have a look at IO::Tee.

--
:wq