my %action = ( this => sub {return "this"}, that => sub {return "that"}, # etc ); # Then later: if (exists $action{$in}) { $action{in}->(); }