use strict; package Foo; use Carp; sub new { my ($class,$msg) = @_; my $self = {msg => $msg}; return bless $self,$class; } sub print_me { my ($self,$cb) = @_; croak "not a code ref" unless ref $cb eq 'CODE'; return $cb->($self->{'msg'}); } package main; my $foo = Foo->new('hello world'); print $foo->print_me(sub {ucfirst shift}), "\n";