my $section = 0; my @sections=(undef,[],[]); while() { $section = $1 and next if /;section([12])/; die "Bad section $section" unless $section; push @{$sections[$section]},$_; }