while (my $row = $dbh -> fetchrow_arrayref) { if ($row -> [$last_name_col] =~ /^[L-Z]/) { push @L_Z => $row; while (my $row = $dbh -> fetch_arrayref) { push @L_Z => $row; } last; } push @A_K => $row; }