my ($i, $j); foreach my $value (sort {$statefinal{$i} cmp $statefinal{$j}} keys %statefinal) { print "$value $statefinal{$value}\n"; }