#!/usr/bin/perl use strict; use warnings; my @k = qw( a b c a b a ); my %i = do { my %h; map { $_ => ++$h{$_} } @k }; print join " ", %i;