use Image::Info qw(image_info); my $filename = "file5.jpg"; # actually a PNG my $info = image_info($filename); if (my $error = $info->{error}) { die "Can't parse image info: $error\n"; } my $mime_type = $info->{file_media_type}; my $suggested_ext = $info->{file_ext}; print "mime type: $mime_type\n"; print "suggested extension: $suggested_ext\n";