#!/usr/bin/perl use strict; my %idcount; while (<>) { if ( /,CO(\d+)\s/ ) { $idcount{$1}++ } } my ( $highest ) = sort { $idcount{$b} <=> $idcount{$a} } keys %idcount; my $total = 0; $total += $_ for ( values %idcount ); print "Highest count was for group CO$highest, with $idcount{$highest} out of $total users\n"; #### Highest count was for group CO12345, with 4 out of 6 users #### my ($maxcount) = sort { $idcount{$b} <=> $idcount{$a} } keys %idcount; my $highest = join(",CO", grep { $idcount{$_} == $maxcount } keys %idcount );