use Module::ScanDeps; my $perl_script = 'whatever.pl'; my $hash_ref = scan_deps($perl_script); for (keys %$hash_ref){ print $_,"\n" if ( $$hash_ref{$_}{'file'} =~ m#/site/# and $_ =~ m#\.pm# ); } # Only capture the name if it IS a module (.pm) and it # isn't in core, (path includes /site/). You may need # to modify the filter if your modules are in non-standard # places. #### use CPAN; my @modules = # module list from the previous script for $mod (@modules){ my $obj = CPAN::Shell->expand('Module',$mod); $obj->install; }