# Sum the proteins' molecular weights. my $sum; # no need to declare $sum until here. # Also no need to initialize to zero; Perl will do that when you add to it. foreach my $AA ( @AA ) { print "AA: $AA Weight: $MWs{ $AA }\n"; $sum += $MWs{ $AA }; }