use strict; use warnings; use CPAN; my $CPAN = CPAN->new(); for my $module (@modules) { my $install = $CPAN->install($module); my $file = "module-name-with-hyphens.txt"; open(my $fh, '>', $file) or die $!; print $fh $install; }