my $cur_section = 0; my %sections; while( ) { if( /^;section(\d+)/ ) { $cur_section = $1; next; } unless( $cur_section ) { warn "No section defined for `$_'\n"; next } push @{ $sections{ $cur_section } }, $_ }