my $txt = <$fh>
This reads the first line from $fh
and assigns it to scoped (my) variable named $txt.
there is nothing wrong with that (it is *not* a copy). The
rest of it however, is suspect. Something like this might be better
use Symbol;
...
socket($SOCK=gensym(), PF_INET, SOCK_DGRAM, $proto);
...
Otherpackage::foo($SOCK)
...
package Otherpackage;
sub foo { my $fh = shift; }