You're very close - as LanX points out, I think defined is what you want.
Something like this (which is not far off from what you already have):
#!perl
use strict;
use warnings;
use Net::Telnet;
sub attemptTelnetCheck {
my ($host) = @_;
my $t = new Net::Telnet(
Errmode => 'return',
Timeout => 2,
Port => 1234
);
my $r = $t->open($host);
if (defined $r) {
$t->close();
print("$host : SUCCESS!\n");
} else {
print("$host : failure. " . $t->errmsg() . "\n");
}
}
my @hosts = (
"192.168.10.1",
"192.168.10.2"
);
for my $host (@hosts) {
attemptTelnetCheck($host);
}
Cheers.