use IO::Tee; open(ERRLOG, '>error.txt'); my $tee = new IO::Tee(\*STDOUT, \*ERRLOG); *STDERR = $tee;