You send a HTTP/1.1 request with keep-alive (which is implicit with HTTP/1.1, so you could skip the Connection header). But, you don't make any attempts to parse the HTTP response, but just assume that it will close the connection when the request is done. This is plain wrong.
I really recommend you to use established HTTP libraries like LWP, HTTP::Tiny ... and not try it on your own. If you really want to do it please read the relevant standard, e.g. RFC 2616 which explains all the important stuff you simply ignore: http response header and body, content-length vs. chunked encoding, content-encodings etc. HTTP/1.1 is not that simple - if you want it simple use HTTP/1.0 and do not use keep-alive.