#!/usr/bin/perl use Data::Dumper; use strict; my $k; my %hash; my @line; # iterate thru data and store values in hash while() { chomp($_); @line = split(",", $_); push @{ $hash{$line[2]} }, $line[4]; } # hash structure (in case you are curious) print "hash structure:\n"; print Dumper(\%hash); print "\n"; # iterate thru hash # send arrays to greatest sub print "greatest values for each key:\n"; foreach $k (keys %hash) { print "$k: " . &greatest( $hash{$k} ) . "\n"; } #return greatest value sub greatest() { my $arr = shift; my @a = sort { $b <=> $a } @{ $arr }; return $a[0]; } exit; __DATA__ 2004,21,21,1,16.00 2004,21,21,1,16.25 2004,22,22,1,18.00 2004,22,22,1,18.25