my @array= qw(1 3 5 7); my @array= qw(1 3 5 7); &test(\@array); sub test { my ($s1,$s2); my @a=@{$_[0]}; for (my $i=0;$i<=$#a ;$i++) { ($s1,$s2)=0; for (my $j=0;$j<=$#a ;$j++) { if ($i == $j) { $s1=$s1+ $a[$j]; } else{ $s2+=$a[$j]; } } } print "\n"; }