use warnings; use strict; use Getopt::Long; GetOptions( 'd|debug' => \(our $DEBUG) ) or die "Bad options\n"; $Foo::DEBUG = $DEBUG; print "Debugging main\n" if $DEBUG; Foo::foo(); my $bar = Bar->new( debug => $DEBUG ); $bar->quz(); { package Foo; our $DEBUG; sub foo { print "Debugging Foo\n" if $DEBUG; } } { package Bar; sub new { my ($class,%args) = @_; my $self = { %args }; return bless $self, $class; } sub quz { my $self = shift; print "Debugging $self->quz()\n" if $self->{debug}; } }