#!C:\Perl\bin use strict; my %games = ( 'john' => '11::Boston vs. Orlando::2004-01-15', 'beth' => '20::Minesota vs. New York::2004-01-15', 'bob' => '5::San Antonio vs. Pittsburgh::2004-01-13' ); my %sorted_on_count_hash = (); while (my($person,$value) = each %games) { my ($count,$game,$date) = split /::/, $value; my $sorted_key = sprintf("%04d", $count); # Zero fill count # so that numeric # part of key is same # length, so that sort # is correct based on # count. $sorted_key .= $person; # add person to key to make key unique # for that person $sorted_on_count_hash{$sorted_key} = { "count" => $count, "game" => $game, "date" => $date }; } my %sorted_on_count_hash = (); foreach my $key (sort keys %sorted_on_count_hash) { print "count=[$sorted_on_count_hash{$key}{'count'}], " . "game=[$sorted_on_count_hash{$key}{'game'}], " . "date=[$sorted_on_count_hash{$key}{'date'}]\n"; } #### ------------------------------------------------------ count=[5], game=[San Antonio vs. Pittsburgh], date=[2004-01-13] count=[11], game=[Boston vs. Orlando], date=[2004-01-15] count=[20], game=[Minesota vs. New York], date=[2004-01-15] ------------------------------------------------------