use Filter::Handle qw/subs/; my @errors; Filter \*STDERR, sub { push @errors, "@_"; () }; print STDERR "bar"; print STDERR "foo"; UnFilter \*STDERR;