use warnings; use strict; use Filter::Handle qw/subs/; open (LOGFILE, ">logfile") || die "could not open logfile"; #filter STDERR through an anonymous sub Filter \*STDERR, sub {local $_ = "@_"; print LOGFILE "Filtered: $_ "; $_}; #prints to both STDERR and to LOGFILE print STDERR "error!\n"; #STDERR will no longer be filtered through your sub UnFilter \*STDERR; close LOGFILE;