sub sum { our @a local *a = shift; my $total = 0; $total += $a[ $_ ] for 0 .. $#a; return $total; } my @data = getNums(); my $sum = sum( \@data );