in reply to Re: Detecting if a string is a regular expression
in thread Detecting if a string is a regular expression

... any $string can be used as a valid regex like in m/$string/ ...

... and you don't even need the  m// or  qr// incantation. The  =~ binding operator can do the trick:

>perl -wMstrict -le "my $s = 'abc'; ;; print 'match' if 'xabcx' =~ $s; print 'match' if 'xabcx' =~ 'abc'; " match match

Replies are listed 'Best First'.
Re^3: Detecting if a string is a regular expression
by LanX (Saint) on Jan 11, 2013 at 00:06 UTC
    yeah I noticed, but normally I prefer the more obvious syntax. (the m is superfluous too =)

    Cheers Rolf

    PS: I know someone will show us now benchmarks demonstrating that at least 3 and half processor cycles are waisted this way ... ;)