#regex way if ($op=~m/^(==|eq|<|>)$/) { ... #hash way my %allowedops=( '=='=>1 , 'eq'=>1 , '>'=>1 , '<'=>1 ); if ($allowedops{$op}) { ...