my @records; while () { if ($_ =~ /^-/) { # New record push @records, []; next; } next if !@records; push @{$records[-1]}, $_; }