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");