openssl rsa -check -in id_rsa-gsg-keypair -noout

↓perlでやると

#!/usr/bin/perl

use strict;
use warnings;

use Crypt::OpenSSL::RSA;

my $id_rsa = shift;
open my $fh, '<', $id_rsa;
my $rsa_text = do {local $/;<$fh>};
close $fh;

my $key = Crypt::OpenSSL::RSA->new_private_key($rsa_text);
if ($key->check_key) {
    warn 'ok';
}