#!/usr/bin/perl -w use strict; use Data::Dumper; ... while ( my $line = ) { # No need to declare $line until here. my @AA = $line; # No need to declare @AA until here. # Might need to split the line, though ... print Dumper \@AA; # See what's really in that array. Note the backslash. ... #### foreach $AA(@AA) { #I want now the sum of protein's molecular weight. $sum += $MWs{ "$AA(@AA)" }; # ^^ # incorrect syntax } #### # 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 }; }