http://www.perlmonks.org?node_id=165195

cadphile has asked for the wisdom of the Perl Monks concerning the following question:

A simple question really: I want to capture the STDERR from commands like croak and cluck into a log file that records all output of my program. I've read the previous comments in Perl Monks and I find the following in the Camel book:
use FileHandle; use Carp qw (cluck croak); my $LOG_FH = new FileHandle( "somefile", "w" ); my $fileno = fileno $LOG_FH; open STDERR, ">&$fileno" or croak "Can't dup STDERR."; cluck "Testing the output of Carp commands.";
(I need to use the $fileno because the ">&" dup operation doesn't work on I/O typeglobs.)

This works fine: all STDERR after this goes into $LOG_FH, but it no longer goes to the terminal.

But what I want is like the command "tee". I want STDERR to go to the terminal window, AND to be duplicated into the $LOG_FH filehandle.

Any clues??

Thanks, -Cadphile