A couple of possibilities come to mind:
- Since you know the record length, you could use an external counter and read them in, appending them to the end of the last record read:
my $count = 0;
my @records = ();
while (<IN>) {
if ($count) {
$records[-1] .= $_;
} else {
push @records, $_;
}
$count = ++$count % 6;
}
print join("\n",@records);
- You could slurp the file and split on a pattern that matches the last line:
my $content = do {
local $/;
<IN>;
};
my @records = split /(?<=Metadata\: 1114890\n)/, $content;
As well, I'm sure, as a multitude of other possibilities. Note that in both the above, the resulting records still contain all the original newlines.