print do {use autodie; open my $fh, '<', 'test.txt'; local $/ = undef; <$fh>}; #### use IO::File; for my $fh (IO::File->new('foo', 'r')) { print $fh->getlines; } # $fh->close is unnecessary. #### use IO::File; print $_->getlines for IO::File->new('foo', 'r');