my %baldata; while (defined($line = )) { if ($line =~/caus/){ $ACTNUM = (split(/\t/,$line))[0]; $CSHBAL1 = (split(/\t/,$line))[17] ; $baldata{$ACTNUM}{$CSHBAL1} = ($ACTNUM,$CSHBAL1); $CSHBAL2 = $baldata{$ACTNUM}{$CSHBAL1}; print "$ACTNUM,$CSHBAL1,$CSHBAL2\n"; } } I can get the value for each KEYID everytime it appears, just can not figure out how to add the values up for each individual ID. Any help will be appreciated.