while ((my $key, my $value) = each (%hash)) { for (my $i=0; $i< @nums; $i++) { if ($key eq $nums[$i]) { push @temps, "$key"; } } } @temps = sort {$a<=>$b} @temps; while ((my $key, my $value) = each (%hash)) { for (my $i=0; $i < @temps; $i++) { if ($key eq $temps[$i]) { push @fluors, "$value"; } } }