# make a new object of type 'Object' and pass it a callback sub my $obj = new Object( sub{print "Hello World"} ); # call a method on that object $obj->method; # when we 'use' an OO module we effectively just add its packages to our code # so lets just write a little package here that has a callback sub package Object; use Data::Dumper; sub new { my $class = shift; my $callback = shift; my $anon_ref = { 'callback' => $callback }; # make object by blessing our anon hash into $class my $object = bless $anon_ref, $class; return $object; } sub method { my $self = shift; print "This is what \$self looks like:\n\n", Dumper($self), "\n\n"; print "And here is our callback sub in operation\n\n"; &{$self->{'callback'}}; }