If you only want the lines upto a unique token, you can set $/ to be that token and the read all the lines in in one go. (See perlman:perlvar and search for $/.
Use split to break these into the individual lines as below.
Note the localization of the setting of $/.
#! perl -sw
use strict;
my $header;
{
local $/ = 'END';
open FILE, "<$ARGV[0]" or die "$!\n";
$header = <FILE>;
#print tell FILE;
close FILE;
}
my @lines = split /\n/, $header;
print $_.$/ for @lines;
That works fine if you only want to read the pre-pended lines. If you want to actually remove them from the file so that you end up with just the binary file again, you could do this with perl but its doubtful if this would be as fast as using tail with a binary offset of the byte after the end token.
The commented out print tell FILE; could be used to get the position to supply the offset for the tail command (eg. tail +nnn file >binonly). This would probably be far more efficient than reading it in and writing it out with Perl as the system utilities have code built in for determining the optimum buffer sizes etc.
There is of course no reason why you shouldn't issue the tail command from within your Perl script:)
Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring! |