http://qs321.pair.com?node_id=1151417


in reply to Executing a "/foo/flags" regex from a string

Here is a small snippet that should do what you were asking for (more or less):

perl -E 'my $str = "/regex/i"; my ($pat, $flags) = $str =~ m{^/(.+)/([imsx]*)\z} ? ($1, $2) : die "Bad regex"; my $qr = qr/(?$flags:$pat)/; say qq{Matched "$_" with $qr} for grep {$_ =~ $qr} qw(foo bar baz reGex)' Matched "reGex" with (?^u:(?i:regex))


my @a=qw(random brilliant braindead); print $a[rand(@a)];