package MyModule; # 'constructor' sub new { # if you call MyModule->new, $_[0] will be 'MyModule' my $class = shift; # $self can be any reference, but usually a hash my $self = {}; # this is the 'magic' that creates the object bless $self, $class; return $self; } sub half { # if you call $m->half(10), $_[0] will be the object my ( $self, $number ) = @_; # proceed as normal return $number / 2; } package main; # now no longer in package, but in script # instantiate object, call constructor my $m = MyModule->new; # yields '5' print $m->half(10);