Sample code for 30+ languages & platforms
Perl

Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem

See more OpenSSL Examples

How to output the public part of a private key: Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

$pkey = chilkat::CkPrivateKey->new();

# Load the private key from an PEM file:
$success = $pkey->LoadPemFile("private.pem");
if ($success == 0) {
    print $pkey->lastErrorText() . "\r\n";
    exit;
}

$pubKey = chilkat::CkPublicKey->new();
$pkey->ToPublicKey($pubKey);

$success = $pubKey->SavePemFile(0,"pubKey.pem");
if ($success != 1) {
    print $pubKey->lastErrorText() . "\r\n";

    exit;
}

print "Success." . "\r\n";