#!/usr/bin/perl -w use warnings; sub total { my(@arr)=@_; my $result; foreach (0..$#arr){ $result += $arr[$_]; } return $result; } my @fred = qw(1 3 5 7 9); my $fred_total = total @fred; print "The total of \@fred is $fred_total.\n";