use vars qw( $log_file ); $log_file = "T:/err.log"; package TeeStderr; use Fcntl qw(:flock); sub TIEHANDLE { my $i; bless \$i, shift } sub PRINT { my $r = shift; print "STDERR $$ ", @_; if ( open my $FH, '>>', $log_file ) { flock $FH, LOCK_EX; print $FH "" . localtime, "\t", "ErrorLog: ", "", $$, " ", @_; close $FH; } } package main; $| = 1; tie *STDERR, "TeeStderr";