my $dtbl = { 1 => sub { $abc = 1 }, 2 => sub { $def = 1 }, 3 => sub { $xyz = 1 }, }; exists $dtbl->{$x} ? $dtbl->{$x}() : $nothing = 1;