@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 modifers $mod = "(?$mod)"; } else { $mod = ''; } foreach (grep /$mod$text/, @stuff) { print $_, "\n"; }