Also, you could use a regex to do this. As well, you could add the 'i' modifier to the regex if you wish to allow case-insensitivity, to allow such things as 'Red', 'GrEeN', 'BLUe':
if ($color =~ /\A(?:red|blue|green)\z/) { # do something here }
Update: Fixed code to use \A and \z as mentioned below by Juerd and merlyn. I still haven't shaken the habit of using the nasty ^ and $ anchors. I also don't like the use of the /s modifier much, so I had best get used to the better-used anchors.
If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.
In reply to Re: OR operator
by Coruscate
in thread OR operator
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |