use Module::Load::Conditional qw[can_load]; # Are we running threads? my $grThreaded = eval 'use threads; 1'; # If so, load thread modules my ($grThreadModules) = { 'threads::shared' => undef, 'Thread::Semaphore' => undef, }; if ( $grThreaded ) { unless ( can_load( modules => $grThreadModules ) ) { print "ERROR: Cannot load threaded modules in $0. Exiting."; exit(); } } use strict; my($gnWarning); if ( $grThreaded ) { # Does not work at all: Undefined subroutine &main::share # share($gnWarning); # This works in the debugger # However, if used in production: # Argument to share needs to be passed as ref # threads::shared::share($gnWarning); # This works at run time # However, if used under the debugger: # Type of arg 1 to threads::shared::share must be one of [$@%] # (not single ref constructor) threads::shared::share(\$gnWarning); }