in reply to Testing ports
You could use IO::Socket (see The Caller section of Perl, Sockets and TCP/IP Networking) to attempt to connect to port 23 of $ip.
If you're running Unix, you should look into nmap, which is designed to do this job for you.