my %hash = (val1 => \&task1, val2 => \&task2, val3 => \&task3); if (exists $hash{$test}) { $hash{$test}->(); }