#!/usr/bin/perl -w use strict; my @array = qw(John Sue Larry Mary John Mary Larry John Joe Lisa John Mary); my %names; # create a hash variable to use for (@array) { $names{$_}++; } for ( keys %names ) { $names{$_} <= 1 ? print $_, ' is repeated for ', $names{$_}, ' time', $/ : print $_, ' is repeated for ', $names{$_}, ' times', $/; }