the eval() solution would work in the above case, but be advised that this approach is even eviler than (string) eval() used on its own. this is because code can be evaluated at run time both in eval() and in the extended regex pattern (?{{ code... }}).
see the subject of taint checking and perlsec for more horrific details.