... my $in_data_section = 0; while (){ chomp; if ($in_data_section) { my @numbers = split; #... } $in_data_section = 1 if m/^Number/; } #### while (){ chomp; if (/^Number/) { # found header, now we're expecting two lines with numbers for (1..2) { $_ = ; chomp; my @numbers = split; #... } } #... do other stuff }