#!/usr/local/bin/perl use warnings; use strict; use Filter::Handle qw/subs/; #open the logfile open (LOGFILE,">>test.log") || die "open: $!"; #set up a sub to filter our output #print @_ to LOGFILE then also print it to STDERR Filter \*STDERR, sub { local $_ = "@_"; print LOGFILE scalar(localtime), ": $_"; $_}; #test it out by printing something to STDERR print STDERR "hello world\n"; #turn off filtering UnFilter \*STDERR; close LOGFILE || die "close: $!";