People have already told you how you can load the module with Perl primitives. There's also Module::Load::Conditional.
If you're looking to access an array of the same name no matter which module you loaded, consider making a method for that so you can skip the symbolic reference stuff. Give each module a method of the same name:
package ReportHashFileFoo;
our @some_package_variable;
sub get_array { \@some_package_variable }
Then, when you load that module:
if( ... some condition ... ) {
eval "use $module" or croak ...;
my $array_ref = $module->get_array;
}
2023 update Lately I've been using require in a state expression since that only happens once in the scope:
use v5.10;
if( ... some condition ... ) {
state $rc = require $module;
my $array_ref = $module->get_array;
}
I don't know what you're really doing (XY Problem), but there's probably a better design. When things seem tricky like this, it's usually because you're overlooking a better way to to it.