I have my code like this:
if ( $var eq \"str1\" || $var eq \"str2\" || $var eq \"str3\" ) { ... }
Is there anyways to optimize this. I want
Depending on the contents of the strings, a regex is quite convenient:
if ($var =~ /^(str1|str2|str3)$/) { … }
Failing that, you can grep over a list:
if (grep { $var eq $_ } qw{str1 str2 str3}) { … }