sub default_code { my ($self,$extra) = @_; my $sub = sub { my ($extra,$optional,$optional) = @_; # do something }; return $sub; } #### $object->display( { my_code => sub { my ($hashref) = shift; foreach (keys %$hashref) { # more code } }; } ); #### sub display { my ($self,$args) = @_; # $args->{'my_code'} has our "custom code" # here is where we determine which one to use my $action = $args->{'my_code'} || $self->default_code; $action->($args); }