use warnings; use strict; package main; my $obj = MyPackage->new(); print "Value: ", $obj->value(), "\n"; package MyPackage; my $var = 20; sub new { my ($class) = shift; my $self = { value => $var }; return bless($self, $class); } # new sub value { my ($self) = @_; return $self->{value}; }