package My::Module; sub new { my ( $class, $param_hr ) = @_; $param_hr = {} unless defined $param_hr; my $self = { # hashref or arrayref key => 0, format => 0, #... }; bless $self => $class; # now your hash is an object of class $class. if( exists $param_hr->{'key'} ){ $self->key($param_hr->{'key'}) } else { warn "param 'key' is required."; return undef } return $self; # return the hash, sorry now blessed into a class instance, hallelujah } # get or set the key sub key { my $self = $_[0]; my $akey = $_[1]; # optional key print "you called key() method on object '$self'\n"; if( defined $akey ){ print "key() : changing key to '$akey'\n"; $self->{'key'} = $akey; } return $self->{'key'}; } 1; package main; # uncomment only if My::Module is in separate file: #use My::Module; # the notation module->new adds "module" as the first argument to the new() params. # so here is how $class is set in your question, although YOU dont pass class, Perl does. my $mod = My::Module->new({ 'key' => 123, }); die unless defined $mod; # the same notation applies when calling the method # Perl passes the object ref ($self=$mod) to the method as a first param print "my key: ".$mod->key()."\n";