The example is of using raw sockets and not an existing HTTP server. Since $ENV{QUERY_STRING} is set by the server *from* data read from the raw socket, it won't be available in this example until it's made available.
I took the code as more of an example on how one could use sockets in Perl than how one ought to do web programming.