use strict; use warnings; use IO::Tee; open my $read, '<', 'Fanggame.txt'; open my $write, '>>', 'Fanggame.txt'; open my $log, '>>', 'loggy.txt'; my $tee_fh = IO::Tee->new($read, $write, $log); my @lines = <$tee_fh>; foreach (@lines){ s/the/beeswax/g; print {$tee_fh} $_; }