use bigint; say 42->bmodinv(2017);

use Math::ModInt qw/mod/;  say mod(42, 2017)->inverse->residue;

use Math::Pari qw/PARI lift/; say lift PARI "Mod(1/42,2017)";

use Math::GMP qw/:constant/; say 42->bmodinv(2017);

use ntheory qw/invmod/; say invmod(42, 2017);