{ package PKG; sub safe_sub { my $self = shift if @_ == 3 and UNIVERSAL::isa($_[0], __PACKAGE__) or $_[0] eq __PACKAGE__; my($hash, $string) = @_; print $hash->{foo}, ':', $string, $/; } sub new { bless {}, shift } } my $obj = PKG->new(); print '$obj->safe_sub - '; $obj->safe_sub({'foo' => 'bar'}, 'cool'); print 'PKG->safe_sub - '; PKG->safe_sub({'foo' => 'bar'}, 'cool'); print 'PKG::safe_sub - '; PKG::safe_sub({'foo' => 'bar'}, 'cool'); package PKG; print 'safe_sub - '; safe_sub({'foo' => 'bar'}, 'cool'); __output__ $obj->safe_sub - bar:cool PKG->safe_sub - bar:cool PKG::safe_sub - bar:cool safe_sub - bar:cool