my $section = 0; my %sections = (1 =>[],2=>[]); while() { push @{$sections{( /;section([12])/ and $section = $1 and next() ) or ( $section || warn "No section defined for: $_\n" and next() )}} ,$_; }