my ($first_key, $first_val) = each(%{$main_hash{$k}[$x]}; #### last if ($x + 1 >= scalar(@{$main_hash{$k}});