my @contents; my $header=; # extract the first line while () { next unless /\S/; # ignore whitespace only lines. if (/^done,(\d+)$/) { die "Count mismatch in trailer. Got $1 expected @{[scalar @contents]}" unless $1 == scalar(@contents); last; } #chomp; # uncomment if you dont want newlines in contents. push @contents,$_; # add the line to the buffer }