my @sorted_keys = sort keys %hash; while (@sorted_keys) { my @ten = splice(@sorted_keys, 0, 10); # Do something with @ten }