#!perl -w use strict; use threads; use Thread; use threads::shared; sub thirdThread { threads->detach(); printf "[%d] Third thread started\n",threads->tid(); } sub secondThread { threads->detach(); while(1) { sleep 2; printf "[%d] Going to start a new thread\n",threads->tid(); threads->create(\&thirdThread); } } threads->create(\&secondThread); while() { print "CMD: ",$_,"\n"; if($_ eq "quit\n") { last; } }