my $section = 0; my @sectone; my @secttwo; while() { if (/;section([12])/) { $section = ( $1 == 1 ? @sectionone : @sectiontwo); } else { push @{$section},$_ and next if $section; warn "No section defined for: $_\n"; } }