#!/usr/bin/perl use strict; use warnings; my @modules = qw(1 2 3 4); my %sub; for my $module (@modules) { if ( -e "$module.pl" and -r "$module.pl" ) { local $/; open my $fh, '<', "$module.pl" or die "cannot open $module.pl: $!\n"; my $perl = <$fh>; close $fh; my $sub = sub { local @ARGV = @_; eval $perl; warn "$module failed: $@\n" if ($@); }; if ($@) { die "$module.pl failed to load: $@\n"; } $sub{$module} = $sub; } else { die "$module.pl does not exist or is not readable\n"; } } for my $sub ( @modules ) { warn "calling $sub\n"; $sub{$sub}->(); } print "finished calling all modules\n";