use IO::File; for my $fh (IO::File->new('foo', 'r')) { print $fh->getlines; } # $fh->close is unnecessary.