foreach $key (sort grep $_, keys %{$obj->somehash}) { . . .