#!/usr/bin/perl use strict; use warnings; my %in; my %out; my $testsub; my $constant = "fixed"; $in{cid} = 12345; $out{this}{that}[0] = 678; $testsub = sub { return "this is foobar" }; print "normally, \$testsub returns: " . &$testsub . "\n\n"; while () { s/(?<=')(\$[^']+)/(ref($1) eq 'CODE') ? &{$1} : $1/ee; print; } __DATA__ select field from table where id!='$in{cid}' update table set field = null where id = '$out{this}{that}[0]' delete from table where value = '$constant' select something from somewhere where status='$testsub' #### normally, $testsub returns: this is foobar select field from table where id!='12345' update table set field = null where id = '678' delete from table where value = 'fixed' select something from somewhere where status='CODE(0x7ff80903f0e8)' #### s/(?<=')(\$[^']+)/$1/ee;