in reply to storing a qr// compiled regexp in a database?

What others have said are roughly correct: you can't get the fruits of the internal regex compilation step. Perl will give you the stringified version easily, but that's not what you were hoping for.

There's one other issue to beware, if you're trying to persist the stringified version of qr// objects: regex creep.

$regex = qr/(this)is[a]test/i; $regex = "$regex"; $regex = qr/$regex/; # simulate freeze/thaw cycle $regex = "$regex"; $regex = qr/$regex/; # simulate freeze/thaw cycle $regex = "$regex"; $regex = qr/$regex/; # simulate freeze/thaw cycle print "regex: qr{$regex}\n"; __OUTPUT__ regex: qr{(?-xism:(?-xism:(?-xism:(?i-xsm:(this)is[a]test))))}
The stringifier and the qr// operator don't bother to collapse all of the redundant or unnecessary buildup of those (?-xism:...) wrappers. You could get a massive hundred-layer wrapper if you carelessly freeze and thaw these objects.

--
[ e d @ h a l l e y . c c ]