my $row = $sth->fetchrow_arrayref; $row->[0] =~ s/\$(\w+)/exists $table{$1} ? $table{$1} : "\$$1"/eg;