my $code = 'print "stuff\n"'; # in your example this would be read from STDIN. eval $code; # <- eval STRING, not eval { BLOCK } $@ and warn "Found an error: $@";