my $x = 0; foreach $i (sort{$a <=> $b} values %hash){ if($x < 10){ print; $x++; } }