#!/usr/bin/perl

use strict;
use IO::File;

my $cert = new IO::File(">./splitcert.pem") || die "Can't open cert.pem: $!\n";
my $key = new IO::File(">./splitkey.pem") || die "Can't open key.pem: $!\n";

while (<>) {
    (/-----BEGIN.*PRIVATE KEY/ .. /-----END.*PRIVATE KEY/) && do {
	print $key $_;
    };
    (/-----BEGIN CERTIFICATE/ .. /-----END CERTIFICATE/) && do {
	print $cert $_;
    };
}
$key->close();
$cert->close();
