http://www.perlmonks.org?node_id=1071577

jar00n has asked for the wisdom of the Perl Monks concerning the following question:

Working on a new script and was hoping to set a variable named $icase and attempt to match a string with this variable used as the operator. So if $icase is defined then it will be equal to 'i' otherwise it'll be undef. With that in mind, is that even logical/efficient/doable? Quick demo to show what I'm seeing:
#!/usr/bin/perl $icase = 'i'; $str = 'ASdf'; if ( 'asdf' =~ /$str/$icase ) { print "it works!\n" }
Which when ran produces this:
$ perl test.pl Scalar found where operator expected at test.pl line 6, near "/$str/$i +case" (Missing operator before $icase?) syntax error at test.pl line 6, near "/$str/$icase " Execution of test.pl aborted due to compilation errors.