in reply to Re: Re: Re: How can grep search based on text or pattern based on user input?
in thread How can grep search based on text or pattern based on user input?

However, Perl does provide the (?modifier) syntax, for putting the modifiers inside the regex: /(?i)abc/ So, to make this into a full example:
@stuff = ('This is Some text.','This is More text.'); $stext = '/some/i'; ($null, $text, $mod) = split(/\//, $stext); if ($mod and $mod !~ /[^ism]/) { # a little sanity checking on the mo +difers $mod = "(?$mod)"; } else { $mod = ''; } foreach (grep /$mod$text/, @stuff) { print $_, "\n"; }
Adjust the sanity checking on $mod however you like. BTW, Perl allows (?x) as well as (?ism), but I figured you wouldn't need that here.