use strict; use diagnostics; my $foo = new Foo; print $foo->getFooKey(); $foo->setFooKey('new value'); print $foo->getFooKey(); package Foo; sub new { #new Foo where "Foo" is the class name my $class = shift; my $self = bless {}, $class; #hashref accessible only within Package Foo; $self->{'fookey'} = 'some value here'; return $self; } sub getFooKey { my $self = shift; return $self->{'fookey'}; } sub setFooKey { my $self = shift; #if there's another param, set that as the value if (@_== 1) { $self->{'fookey'} = shift; } return $self; } 1; # some value here # new value # This is perl, v5.8.8 built for i686-linux