package MyFilehandler; my $fh; sub openForRead { my $class = shift(); my $filename = shift(); bless \$filename, $class; open FH, '<', $filename or die "could not open file: $!"; $fh = \*FH; sub writeOut { my (@lines) = <$fh>; print @lines; }; } close $fh; writeOut( my $testfh = MyFilehandler->openForRead('somefile') );