use strict; use warnings; use 5.010; use Data::Dumper; package foo; sub new { my $class = shift; my $self = { state => 'uninitialized', }; bless $self, ref($class)||$class; return $self; } sub state { my $self = shift; return $self->{state}; } sub set_state { my $self = shift; my $value = shift; $self->{state} = $value; } package main; # make new object my $foo = foo->new; # show initial state say $foo->state; # change state $foo->set_state('other value'); # show new state say $foo->state; # see what is $foo say "This is \$foo:\n", Data::Dumper->new( [ $foo ], [ '*foo' ] )->Dump;