in reply to SSL on a TCP connection

Others will undoubtedly offer a Perl solution, meanwhile an easy way which works well is to use an SSL wrapper such as stunnel or sslwrap.