Earlier quoted context omitted.
sub foo { if (whatever) { open my $fh, ...; return $fh; } else { return \*STDOUT; } } will do the job.
Thanks. I feel certain that I tried exactly this a long time ago, and it didn't work as expected, but I may be misremembering. I'll give this a shot the next time I'm in front of a keyboard -- if it works, it will be nothing short of healing.
demeisen=; perl -e 'my $in_fh = (defined $ARGV[0] and $ARGV[0] ne "-") ? do { open my $fh, ";'
HELLO
Line: HELLO
demeisen=; perl -e 'my $in_fh = (defined $ARGV[0] and $ARGV[0] ne "-") ? do { open my $fh, ";' -
HELLO
Line: HELLO
demeisen=; echo 'HI' >tmp/hi
demeisen=; perl -e 'my $in_fh = (defined $ARGV[0] and $ARGV[0] ne "-") ? do { open my $fh, ";' tmp/hi
Line: HI
demeisen=;