use strict; use warnings; { package Fruit; sub new { my $class = shift; my $fruit = shift; my $self = { name => $fruit, color => 'red' }; bless $self, $class; }; sub set_color { my $self = shift; $self->{'color'} = shift; }; sub get_color { my $self = shift; $self->{'color'}; }; } my $obj = Fruit->new('apple'); $obj->set_color('green'); $obj->get_color; use Data::Dumper; print Dumper($obj);