in reply to check if a value is in a given set

I tend to use hashes if the set is larger, but I stay with grep if not and the test is not repeated much:
#!/usr/bin/perl use warnings; use strict; my @values = qw/banana plum apple strawberry pea/; my $var = 'apple'; my %hash; undef @hash{@values}; print exists $hash{$var} ? "yes\n" : "no\n"; print +(grep $_ eq $var, @values) ? "yes\n" : "no\n";