++ for tagging it as homework, providing code, errors, etc.
You have been given some advice already, let me add my $0.02.
- @_ contains the parameters to a sub. See (original) lines 11 for use, and line 14/15 for lack of use.
- Declare variables as close to use as possible (usually). Line 16 => foreach my $a (@list_of_numbers) {. See also your use of $i on line 15. Declare it right there.
- Your requirements state that you want to return the list of numbers. Are you sure you want to print on line 18? Perhaps grep would help. As an example, to return a set of numbers that are between 4 and 8, you could do something like grep { $_ > 4 && $_ < 8 } @numbers. This could probably be used to replace you entire foreach loop. Conversely, look at push to store the results within your foreach loop.
- Line 15 does not do what you think it does. You are using ==, a comparison operator, when you want =, an assignment operator.
- Instead of the call on line 18 to mean(@list_of_numbers) (which does not do what you think it does within the string), why not just use $i, which you have already calculated.
- I would probably choose different variable names. $a => $number, $i => $mean, @list_of_numbers => @numbers. The '@' sigil indicates an array, so 'list_of_' is redundant. $i needs me to look back to its assignment to remember what it actually holds. $a is not as far, but it has the same problem. Anything that can be done to keep the person from having to backtrack when reading your code makes it easier to read.
- Kudos on using List::Util for calculating the sum. Easy enough to do by hand, but since that isn't the purpose of the exercise, there is no sense cluttering up the assignment with support code.