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