use Math::Polynomial::Solve qw!poly_derivative poly_roots!; my %haystack; my $rep = int 5; # $rep means right endpoint of the interval [0, $rep] foreach ( $a = 1; $a <= $rep; $a++ ) { foreach ( $b = 1; $b <= $rep; $b++ ) { foreach ( $c = 1; $c <= $rep; $c++ ) { if ( $a == $b || $b == $c || $c == $a ){ next; } else { # expanded form of (x^2)*(x - a)*(x - b)*(x - c) # coeffs are in an array my @quintic = (1, -$a - $b - $c, $a*$b + $a*$c + $b*$c, -$a*$b*$c, 0, 0); my @derivative = poly_derivative(@quintic); my @zeros = poly_roots(@derivative); $haystack{@quintic}{@derivative} = @zeros; } } } }