#!/usr/bin/perl -w use strict; use IO::Socket::INET; my @host = ('192.168.1.3', '192.168.46.2'); my $port = '22'; my ($connected); foreach (@host){ check($_); } sub check { my $ip = $_[0]; my $sock = IO::Socket::INET->new(PeerAddr => $ip, PeerPort => $port, Proto => 'tcp', timeout => '10') and $connected = 1; print "$ip is listening on port $port\n" if $connected; print "$ip is NOT listening on port $port.\n" unless $connected; }