in reply to Anonymous Subroutine

It is faster and less error prone to use the summation formula rather than doing the brute force summation.
use strict; use warnings; my $number = $ARGV[0]; my $sum_of_squares = sub{ my $n = shift; return $n * ($n + 1) * (2*$n +1) / 6; }; print $sum_of_squares->($number);

This formula is available in many places. I first found it at https://brilliant.org/wiki/sum-of-n-n2-or-n3/.

Bill