#!/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'