#!/usr/bin/perl package MyFH; sub TIEHANDLE { my $class = shift; return bless { @_ }, $class; } sub READLINE { my $self = shift; print "reading line from remote file $self->{file} ...\n"; # ... (your implementation here) my $line = "foo\n"; my @lines = ("foo1\n", "foo2\n"); return wantarray ? @lines : $line; } sub PRINT { my $self = shift; print "writing line(s) to remote file $self->{file} ...\n"; # ... (your implementation here) print "wrote: @_\n"; } package main; use Symbol 'gensym'; my $fh = gensym(); # get ref to anonymous glob tie *$fh, "MyFH", "file" => "foo.txt"; my $line = <$fh>; print "read: $line\n"; print $fh "bar", "baz"; #### reading line from remote file foo.txt ... read: foo writing line(s) to remote file foo.txt ... wrote: bar baz