use strict; use warnings; use Tie::IxHash; my (%hash1); tie %hash1, "Tie::IxHash"; #To maintain the order my @array = ("one", "two", "one", "three", "four", "one", "two"); $hash1{$_}++ for (@array); my $hash = \%hash1; print "$_ => $hash->{$_}\n" for ( keys %{$hash}); #Dereference and print outputs: -------- one => 3 two => 2 three => 1 four => 1