my $max = 0; my $pop; my $cnt = 0; sort @ary; while ($cnt < @ary) { if ($ary[$cnt] eq $ary[$cnt+$max]) { $pop = $ary[$cnt]; while ($ary[$cnt] eq $ary[$cnt+$max]) { $max++; } $cnt += $max } else { $cnt ++; } } print "$pop, the most popular element, appears $max times";