use if eval { require mod; 1 }, qw' constant haveMod 1 '; #### use constant haveMod => eval { require mod; }; #### use constant { map { no strict 'refs'; ( my $constant = $_ ) =~ s/:://g; "have$constant" => ${"${_}::VERSION"} } qw( Foo::Mod Bar::Mod ); };