use warnings; use strict; use IO::Tee; open( my $log_fh, ">>", "mylog.txt" ) || die "Can't open the log for writing: $!"; my $output = IO::Tee->new( \*STDOUT, $log_fh ); print $output "Starting the script...\n";