You can use File::LibMagic which uses the same library as the unix file
command.
On ubuntu, I installed it as:
apt-get install libmagic-dev
cpan File::LibMagic
For windows, it is known to work with Cygwin, and it should work with windows if you can install the libmagic libraries. I haven't tried this, so YMMV.
Example
#!/usr/bin/env perl
use warnings;
use strict;
use File::LibMagic;
my $magic = File::LibMagic->new();
my $key_dsa = '/home/felix/.ssh/id_dsa.pub';
my $info_dsa = $magic->info_from_filename( $key_dsa );
print "[ $key_dsa ] : " . $info_dsa->{description} . "\n";
my $key_rsa = '/home/felix/.ssh/id_rsa.pub';
my $info_rsa = $magic->info_from_filename( $key_rsa );
print "[ $key_rsa ] : " . $info_rsa->{description} . "\n";
Output
[ /home/felix/.ssh/id_dsa.pub ] : OpenSSH DSA public key
[ /home/felix/.ssh/id_rsa.pub ] : OpenSSH RSA public key