Print the versions of installed Perl modules

This Perl program prints out the versions of installed modules. You give it a list of modules on the command line, and it outputs the modules and their versions, or an error message if the module is not installed.

The output is formatted so that it can be copied and pasted directly into the PREREQ_PM of Makefile.PL. See The files in a Perl module for more about CPAN files.

use warnings;
use strict;
my @modules = @ARGV;
for my $module (@modules) {
    eval "require $module";
    if ($@) {
        my $error = $@;
        if ($error =~ /Can't locate/) {
            warn "$module is not installed.\n";
        else {
            warn "$module had a problem: $@.\n";
    my $version = $module->VERSION ();
    print "'$module' => '$version',\n";


The program output looks like this:

$ perl Gzip::Faster Template Scalar::Util
'Gzip::Faster' => '0.14',
'Template' => '2.26',
'Scalar::Util' => '1.42',

Web links

Copyright © Ben Bullock 2009-2021. All rights reserved. For comments, questions, and corrections, please email Ben Bullock ( or use the discussion group at Google Groups. News about the site. / Privacy / Disclaimer