You can do it slightly differently by putting the regex modifier(s) inside the regex:
use strict; use warnings; my $opts = "io"; my $regex = "test"; while (<DATA>) { my $line = $_; print $line if $line =~ /(?$opts)\Q$regex\E/; } __DATA__ untested unknown
Note that this reveals a slight problem - I can't find your 'o' modifier in the docs. Note also that I have wrapped the regex itself in \Q\E to prevent problems if it contains metacharacters.
Regards,
John Davies
In reply to Re: Is there any way to put regex modifiers into a variable?
by davies
in thread Is there any way to put regex modifiers into a variable?
by hilitai
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |