#! perl -w use strict; package Test; sub new { my $class = $_[0]; my $self = {'associations' => undef, 'balance_by' => undef, 'comment' => undef}; bless $self, $class; return $self; } sub balance_by { my $self = shift; my $entry = shift; my %valid_params = map {$_ => 1} ('foo', 'bar'); unless (defined $self->{'balance_by'}) { $self->{'balance_by'} = (defined $entry && $valid_params{$entry}) ? $entry : 'foo'; } return $self->{'balance_by'}; } my $lex = Test->new(); $lex->balance_by('bar'); print $lex->balance_by();