I guess that this code should answer your question:
use strict;
use warnings;
my @keys = qw/one two three two/;
my %hash;
for my $key (@keys)
{
$hash{$key}++;
}
for my $key (keys %hash)
{
print "$key: ", $hash{$key}, "\n";
}
Output:
three: 1
one: 1
two: 2
The iteration can be simplified to:
$hash{$_}++ for (@keys);
(See $_
in perlvar.) And you can even write something like this:
$hash{$_}++ or print "Found new value: $_.\n" for (@keys);
Which reports each key the first time it’s found.