# Above all others, add: use strict; # Some stuff here my %connection = ( pop3 => { PeerAddr => 'mail.test.com', PeerPort => 110, }, # Add the others here, like above ); my %socket; while (my ($name, $values) = each %connections) { $socket{$name} = IO::Socket::INET->new( Timeout => 1, Proto => 'tcp', ( map { $_ => $values->{$_} } keys %$values ), ); } my $UP = 'Up'; my $DOWN = 'Down'; my $mail = ($socket{pop3} && $socket{smtp} ? $UP : $DOWN); # Do other checks here