#!/usr/bin/perl use 5.008; # 5.8 required for "stable" threading use strict; use warnings; use threads; use threads::shared; use IO::SOCKET; for (my $i = 0; $i < 5; $i++) { threads->create(\&start_thread, "www.yahoo.com:80")->detach; # threads->create(\&start_thread, "www.yahoo.com:80")->join; #works, but who cares :) } sleep(5); print STDERR "done\n"; exit; sub start_thread { my $hostport = shift; my $tid = threads->self->tid; print STDERR "Connecting $tid\n"; my $socket = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $hostport); $socket or die "[$!]\n"; $socket->autoflush(1); close($socket); print STDERR "Closing $tid\n"; }