in reply to Having problems with addition in sub

It has already been mentioned that
foreach (@_) { $number += @_[$_]; }
should be
foreach (@_) { $number += $_; }
If you wanted $_ to have the indexes, you'd use
for (0..$#_) { $number += $_[$_]; }

Another way is to use highly efficient sum from the core module List::Util.

use List::Util qw( sum ); my @fred = qw{ 1 3 5 7 9 }; my $fred_total = sum @fred; my $line = <STDIN>; my @nums = split ' ', $line; my $user_total = sum @nums;