my ($bestVal, $bestKey) = (-1); foreach my $key (@keys) { if ($hash{$key} > $bestVal) { ($bestVal, $bestKey) = ($hash{$key}, $key); } } print "The most frequent word in $ARGV[0] is $bestKey, which was seen $bestVal times.\n";