http://www.perlmonks.org?node_id=803372


in reply to store module names in an array

You could wrap it in a string eval like so:

for my $dbh ( @dbf ) { die $@ if ! eval "use $dbf; 1"; }

I might be inclined to put the whole thing in a BEGIN block.

BEGIN { my @dbf = ...; for my $dbf ( @dbf ) { require $dbf; $dbf->import(); } }

Either way, there's a big security risk if @dbf comes from an untrusted source, but I think the risk is bigger with eval. It might be useful to read the documentation for use and require to see how close they are to what you want to do.