#!/perl/bin/perl use warnings; use strict; my @arr = qw(AB1 BX6 WF2 CB7 EZ6 WY2 AB1 AB1 WF2 ET9); my $hash = {}; for my $cur (@arr) { if (exists($hash->{$cur})) { $hash->{$cur}++; } else { $hash->{$cur} = 1; } } my @unique = sort keys %$hash; for (@unique) { print sprintf qq(Value "%s" occurred %d times.\n), $_, $hash->{$_}; }