package Foo; use warnings; use strict; use Exporter qw(import); our @EXPORT_OK = qw(function_or_method); our %EXPORT_TAGS = (all => [@EXPORT_OK]); sub new { return bless {}, shift; } sub function_or_method { # Throw away the first param if: # A) it's defined, and # B) it's either the class, or an object of the class if (defined $_[0]) { shift if $_[0] eq __PACKAGE__ || ref $_[0] eq __PACKAGE__; } # Now we grab the remaining params (if expecting any) my ($call_num, $call_type) = @_; print "Num: $call_num called as $call_type\n"; } #### use warnings; use strict; use lib '.'; use Foo qw(:all); # Call as function function_or_method('1', 'function'); # Call as method my $obj = Foo->new; $obj->function_or_method('2', 'method');