ap.pm: package ap; sub new { my $self = {}; bless $self; #comment this will cause the error you described. return $self; } sub item_id { my $self = shift; if (@_) { $self->{ITEM_ID} = shift; } return $self->{ITEM_ID}; } 1; ap.pl: use ap; use strict; my $a = new ap; $a->item_id(10); print $a->item_id();