in reply to if (STDERR == STDOUT)

Untested, but I've written something similar before:
sub dev_ino_of_handle { join " ", (stat shift)[0, 1] } sub send_maybe_both { my $text = shift; print STDOUT $text; print STDERR $text unless dev_ino_of_handle(\*STDOUT) eq dev_ino_of_ +handle(\*STDERR); } ... send_maybe_both("HEY!\n");