open STDERR, ">errlog.txt" or die "Whoa! I can't even log my errors: $!"; #### open ERRLOG, ">errlog.txt" or die; $SIG{__WARN__} = sub { my ($msg) = @_; $msg ||= q{Warning: something's wrong}; # Add the file and line number to $msg here # using the return values from caller(). print ERRLOG, $msg; };