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; } } } } #### # the arrays of zeros are now the keys %haystack = reverse %haystack; # supposed to search the keys for zero sets that only contain numbers within 0.0001 of an integer my @wants = grep { / (.*\.0000.*)|(.*\.9999.*) / } keys %haystack; # supposed to print out the corresponding values from %haystack print Dumper{ values of a, b, c corresponding to the elements of @wants };