Here is how I usually do it:
1. Create a separate module with all the shared staff:
package Common;
use constant GLOB_DEBUG_MODE = 1;
use constant GLOB_SITE_NAME = 'My site';
1;
2.
use Common; from anywhere that I need. For example:
package Main;
use Common;
sub print_message {
my $msg = shift;
# Use default site name if no message specified.
unless ($msg) { $msg = Common::GLOB_SITE_NAME; }
# Prepend with "DEBUG: " if in debug mode.
$msg = "DEBUG: $msg" if (Common::GLOB_DEBUG_MODE);
print $msg;
}
1;
Update: I've answered a bit a wrong question. :) You were asking about global variables, while I described constants. :)
Update: Fixed two misplaced 'Common's. :)