my $allowed = sub { grep $_[0] == $_, 10022, 96813, 55401 }; if ($allowed->($redis_handle->get('key')) { # do something }