if (defined $arg) { if (ref($arg) and UNIVERSAL::isa($arg, 'IO::Handle')) { $ioref = $arg; } elsif (tied($arg)) { my $class = ref($arg); no strict 'refs'; $ioref = $arg if defined &{"${class}::TIEHANDLE"}; } else { require IO::Handle; eval { no strict 'refs'; $ioref = *{$arg}{IO} if defined *{$arg}; }; undef $@; } }