#!/usr/bin/perl use strict; use warnings; package Foo; sub new { my $class = shift; bless { name => 'foo' }, ref($class)||$class; } sub bar { my $ref = ref $_[0]; if ($ref eq __PACKAGE__) { ## OO method call oo_bar (@_); } elsif ($ref eq 'HASH') { ## imperative subroutine call with hashref as first element im_bar (@_); } } sub oo_bar { my $self = shift; print "oo_bar got object named ", $self->{name}, "\n"; } sub im_bar { my $hr = shift; print "im_bar got hashref with name ", $hr->{name}, "\n"; } 1; #### #!/usr/bin/perl use strict; use warnings; use Foo; my $hr = { name => 'hashref' }; my $obj = new Foo; ## OO method call $obj->bar; ## imperative call, but since $obj is a blessed object, ## this is equivalent to the OO call Foo::bar($obj); ## imperative call Foo::bar($hr);