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

diotalevi has asked for the wisdom of the Perl Monks concerning the following question:

In the regexp /(?{ ... })XXX/, I would like to ensure that the code block is run. When that pattern is applied to " failed ", the optimizer quickly notes that XXX is a required literal and doesn't appear in the string. My code block never fires. Can I force the issue somehow?

" failed " =~ /(?{ $ok = 1 })XXX/; print $ok ? "Good" : "Bad";

Compiling REx `(?{ $ok = 1 })XXX' size 5 Got 44 bytes for offset annotations. first at 1 1: EVAL(3) 3: EXACT <XXX>(5) 5: END(0) anchored `XXX' at 0 (checking anchored) minlen 3 with eval Offsets: [5] 1[14] 0[0] 15[3] 0[0] 18[0]
Guessing start of match, REx `(?{ $ok = 1 })XXX' against ` failed '... Did not find anchored substr `XXX'... Match rejected by optimizer