Got the credentials for Service Account from Developer Console
First, I converted p12 private key to PEM:
openssl pkcs12 -in
I don't know why, but the problem was with curl.
I replaced it by WWW::Mechanize:
my $mech = WWW::Mechanize->new( autocheck => 1 );
$mech->post('https://accounts.google.com/o/oauth2/token',
'Content-Type' => 'application/x-www-form-urlencoded',
'Content' => [
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $token_request,
],
);
and it works.