#!/usr/bin/perl -w use strict; use Data::Dumper; my @this_record; #lines of the record my @records; #array of array while () { chomp; if (my $line = m|^LOCUS|...m|^//|) { if ($line =~ m/E0$/) #don't push the trailing "//" { push (@records, [@this_record]); #record complete @this_record = (); } else { push (@this_record,$_); #just another record line } } } print Dumper \@records; __DATA__ LOCUS NP_644805 770 aa linear PRI 06-FEB-2011 ...following lines deleted for brevity ...