in reply to Reading a Filehandle by line or by stream

Make perl think your header is one line:

my $header; { local $/ = 'END'; open FH, "< $filename" or die $!; $header = <FH>; close FH or die $!; }

Localizing $/ in brackets cuts out bad side effects, and just reading to the marker gives you minimal read length.

After Compline,
Zaxo