in reply to Why I got so many CLOSE_WAIT
CLOSE_WAIT is not dealt with by perl at all. It's all done at the OS level. More specifically, it's part of the TCP stack.
There's not much you can do about it other than tuning your operating system parameters.
I had a similar situation on a Windows box a few years ago. I had large numbers of quite frequent connections from both mysql and a server I had written in perl, much like yours. I also found the CLOSE_WAIT staes giving me anguish. In the end I had to tell Windows to back off the time it held a connection in CLOSE_WAIT state. Down to only a few seconds, I think it was.