#!/usr/bin/perl package myClass; use strict; use warnings; ### Pure-cheese useless constructor sub new { bless {}, __PACKAGE__ } ### Bimodal sub sub someFunction { my $self = shift if @_ && UNIVERSAL::isa( $_[0], 'UNIVERSAL' ); my $otherArg = shift; print "Called as ", defined $self ? "method" : "function", " with '$otherArg' argument.\n"; } package main; use strict; use warnings; # Invoked as a function myClass::someFunction( "function thingie" ); # Invoked as a method my $testThingie = new myClass; $testThingie->someFunction( "method thingie" ); # It even works invoked as a static method myClass->someFunction( "static method thingie" );