use warnings; use strict; my %drinkType = ('coffee' => \&doNonalky, 'beer' => \&doAlky, 'whisky' => \&doProperAlky); my $drink; my $punter = 'coffee'; if (exists $drinkType{$punter}) { $drinkType{$punter}->(); } else { print 'unknown'; } sub doNonalky { print 'non alky'; } sub doAlky { print 'alky'; } sub doProperAlky { print 'proper alky'; }