my $total; sub Build_totals_shares_for_sedol_Sell_side($$$) { my $sedol = shift; my $shares = shift; my $mySellfirstflag = shift; if ($mySellfirstflag eq "YES") { %Sellhash = ($sedol => $shares); #Do you mean that with mySellfirst that we should replace the shares, #If so, the above line should be $Sellhash{$sedol}=$shares. #As it stands now, we replace the entire hash!! print "Sell: The $sedol has traded\n$share\n"; } else { if (exists $Sellhash{$sedol}) { print "the sedol is in the list so add the shares.\n"; $Sellhash{"$sedol"} += $shares; my $newtotal = $Sellhash{"$sedol"}; print "the new total shares for sedol: $sedol is $newtotal\n"; } else { $Sellhash{$sedol} = $shares; #You did a .= here was that a typo? print "the new entry is $sedol $shares\n"; } $total=0; $total += $_ foreach values %Sellhash; } }