use Filter::Handle; local *DEBUG open DEBUG, ">debuglog" or die $!; my $f = Filter::Handle->new(\*DEBUG); print DEBUG "Foo"; print DEBUG "Bar";