http://www.perlmonks.org?node_id=791374


in reply to Redirect Subroutine Output

You could write the sub the following way:
use warnings; use strict; sub print_to { print {$_[0]} $_[1]; } print_to (*STDOUT, "test stdout"); print_to (*STDERR, "test stderr");