Transformed the shell script to perl, keeping only one connection open.

Hi!

Thanks for making your script available. I'd like to contribute an alternative version using perl.

P.