in reply to Jumping out of a partially read file

Yep, what BUU said. Even though you're jumping out early, be sure and close the filehandle before moving on.

Since you say that there is a special marker signifying the end of the header section, you may also be able to save yourself some time and trouble by setting $/ to that marker. Then you won't even need to loop. To read the header section and nothing else, do this:

local $/ = '<END_OF_HEADERS>'; # change this to what the marker really + is open FILE, $file or die "Couldn't open '$file': $!\n"; my $header = <FILE>; close FILE;
Now your header section is contained in $header. Hope this helps!