#!/usr/bin/perl use strict; use warnings FATAL => 'all'; my @colours = ( "red", "green", "yellow", "green", "yellow", "green", "blue", "red", "green"); my %count; $count{ $_ }++ for @colours; print "$_\t$count{ $_ }\n" for keys %count; __END__ output green 4 blue 1 red 2 yellow 2