my @rec; while (<$fh>) { push @rec, $_; if (/^Metadata:/) { do_something_with_record(\@rec); @rec = (); } }