>perl -wMstrict -e "use 5.014; ;; package Foo { ;; sub new { bless [] }; ;; sub msg { my $self = shift; my ($destination) = @_; printf qq{On my way to '%s'. }, $destination; my $coderef = $self->can($destination); return print qq{Cannot get there. \n} unless $coderef; $self->$coderef($destination); } ;; sub Berlin { my $self = shift; print qq{I am in $_[0]! \n}; } ;; sub Paris { my $self = shift; print qq{Arrived in $_[0]! \n}; } ;; } ;; my $obj = Foo->new; $obj->msg('Berlin'); $obj->msg('Paris'); $obj->msg('London'); " On my way to 'Berlin'. I am in Berlin! On my way to 'Paris'. Arrived in Paris! On my way to 'London'. Cannot get there.