foreach $AA(@AA) { #I want now the sum of protein's molecular weight. $sum += $MWs{ "$AA(@AA)" }; # ^^ # incorrect syntax }