For Perl 5 there is Math::GSL::Roots - Find roots of arbitrary 1-D functions
https://metacpan.org/pod/Math::GSL::Roots
Raku has support for using Perl 5 code or can access the GSL C library directly, can't it?
$fspec = sub {
my ( $x ) = shift;
# here the function has to be inserted in the format
# return leftside - rightside;
return ($x + $x**2) - 4;
};
gsl_root_fsolver_alloc($T); # where T is the solver algorithm, see link for the 6 type constants, e.g. $$gsl_root_fsolver_brent
gsl_root_fsolver_set( $s, $fspec, $x_lower, $x_upper ); # [$x_lower; $x_upper] is search interval
gsl_root_fsolver_iterate($s);
gsl_root_fsolver_iterate($s);
gsl_root_fsolver_iterate($s);
gsl_root_fsolver_iterate($s);
gsl_root_fsolver_iterate($s);
my $result = gsl_root_fsolver_root($s);
gsl_root_fsolver_free (s);
There are enhanced algorithms available (gsl_root_fdfsolver_*), if the derivative of a function is available.
See also https://www.gnu.org/software/gsl/doc/html/roots.html#examples for general usage