use IO::Tee; open my $ofh, '>>', 'LOGFILE.txt' or die "Cannot append to 'LOGFILE.txt':$!"; my $tee = IO::Tee->new(\*STDOUT, $ofh); # Prints to both file and stdout #my $tee = IO::Tee->new(\*$ofh);Prints to file only print $tee "Opening $name";