$code = "print 'Hello World.'"; # This may have come for your DB $sub = eval "sub { $code }"; # use eval and string interpolation to convert it into an anon. sub $sub->(); # Execute the sub; # To pass arguments to the sub, do this: $sub->($a1, $a2); #etc # You can capture the return value too $ret = $sub->();