in reply to Using arbitrary packages

eval "use $foo"; die $@ if $@ # die with error message if it failed
will do it but it will do it at runtime, whereas a genuine use will do it at compile time. If you do
BEGIN { my $foo = get_a_module_name(); eval "use $foo"; die $@ if $@ }
it will happen at compile time, you just need to be careful that $foo has a value at compile time.