my $data = []; my $section = 0; while () { if (/^section(\d)/) { $section = $1; } else { next unless $section; push (@{$data->[($section - 1)]}, $_); } } #my @section_one = @{$data->[0]}; # if absolutely #my @section_two = @{$data->[1]}; # neccessary only