$code = 'whatever'; eval qq(return 1; $code); if($@) { chomp($@); print "Syntax error: `$@'\n"; } else { print "Syntax ok\n"; }