#!/usr/local/bin/perl package Sample; use strict; use warnings; sub new { my ($class, %hash) = @_; my $obj = bless \%hash, $class; return $obj; } sub greet { my ($self) = @_; return $self->{greet}; } 1; Package main; use strict; use warnings; my $smp = Sample->new(greet => "hello"); print $smp->greet . "\n";