package test; use strict; use warnings; our $self; sub debug { $self->{'debug'}->(@_); } sub new { my ($class, %params) = @_; my $self = { debug => sub {}, %params }; bless $self, $class; return $self; } sub method1 { local ($self) = @_; debug "Entering method1"; } package main; use strict; use warnings; my $t1 = test->new( debug => sub { print STDERR "debug: @_\n"; } ); my $t2 = test->new( debug => sub { print STDERR "DEBUG: @_\n"; } ); $t1->method1; $t2->method1;