use Tie::Hash::Sorted; tie my %s_hash, 'Tie::Hash::Sorted'; print tied( %sorted_data )->Count, "\n";