sub in_list { my $needle = shift || q{}; # or croak, your choice. croak 'expecting haystack' if not @_; return grep m/^$needle$/, @_; } if (in_list($var, qw(A B C))) { ... }