in reply to Rook question
One of the trickiest notions in Perl is the issue of contexts. When you wrote $sum += @_, you used an @array value in a $scalar context. That changes what it does.
For debugging such things, I would insert a statement within the loop that prints useful information to the STDERR file, e.g.:
print STDERR "sum is $sum\n";.
All interactive programs have two output streams, STDOUT and STDERR, the latter intended for error or diagnostic outputs.
Also, get used to now putting these two statements at the start of every program: