if ($key eq $first .. $key eq $last) { $in = 1; push @keys, $key; } elsif ($in && $key eq $last) { push @keys, $key; } else { $in = 0; } #### if ($key eq $first ... $key eq $last) { push @keys, $key; if ($key eq $last) { # do something to process this record in @keys # assuming that there will be a new record # starting with $first on a subsequent line } }