my @sockets; foreach my $i (0..9) { $sockets[$i] = new IO::Socket::INET( PeerAddr => '127.0.0.1', PeerPort => '389', Proto => 'tcp', ); die "Could not create socket: $!\n" unless($sockets[$i]); } # Use the sockets here as $sockets[1], $sockets[2], etc.