my($favorite_color) = ''; # get some kind of input here my $action = { 'red' => sub { 'the color is red.' }, 'yellow' => sub { 'the color is yellow.' }, 'blue' => sub { 'the color is blue.' }, }->{$favourite_color} || sub { 'I do not know that color' }; print $action->();