{ package Foo; use Scalar::Util 'blessed'; sub _process_calling_convention { # discard pkg name, if called as class method: @_ && !ref($_[0]) && $_[0] eq __PACKAGE__ and shift; # return object, if called as object method: @_ && (blessed($_[0])||'') eq __PACKAGE__ ? shift : () } sub bar { my $obj = &_process_calling_convention; if ( defined $obj ) { print "called as object method $obj->( @_ )\n"; } else { print "called as function ( @_ )\n"; } } } # main: test: my $x = bless {}, 'Foo'; print "\nplain module function call:\n"; Foo::bar(); Foo::bar("arg"); print "\nclass method call:\n"; Foo->bar(); Foo->bar("arg"); print "\nobject method call:\n"; $x->bar(); $x->bar("arg");