Caveat: If you're going to use IO::Socket, you will also need to read the pod for IO::Select to keep connect() from blocking, when you reach a host that is down or has port 23 firewalled.
I agree to the above post,
nmap is a much better solution. Also, nmap logfiles are easily parsable in Perl.