in reply to Jumping out of a partially read file

You are not forced to read the whole file. You can read a few bytes and close it; there is nothing wrong with that.
In your case, since the information that you're looking for is always at the beginning of each file, and you have a way of identifying when each header ends you can do the following.
local $/ = "HEADER END\n"; # set input record separator while ($file = <*.las>) { open(FILE, $file) || die "Couldn't open $file : $!\n"; my $header = <FILE>; close(FILE); # process $header here }
One thing I should mention here is this. Setting $/ simplifies things greately. But! If you're processing large files (you mentioned something about them being 40MB) then you better be sure they all contain those headers that you're talking about. If not, the whole file will be slurped into memory.

If you want to avoid that, you can do something along these lines
my $maxHeader = 50; OUTER: while ($file = <*.las>) { open FILE, $file or die "Couldn't open $file : $!\n"; my $header = ''; while (<FILE>){ $header .= $_; last if $_ eq "HEADER END\n"; if ($. > $maxHeader){ print "Invalid file format : $file\n"; close FILE; next OUTER; } } close FILE; # process $header here }
Hope this helps. --perlplexer