Lexicals aren't "quirky" here. They are just used like any other closure. You just aren't convincing perl that it should go to the trouble of recompiling your regular expression each time. If you start your regex with something like (?#@{[rand]}) then you'll have a nicely random part of your regex to get it to recompile each time.