#!/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";