use warnings; use IO::Handle; use threads; use strict; use DBI; use Email::MIME; use Email::Sender::Simple qw(sendmail); while () { chomp(my $msg = $_); print "Received: $msg\n"; if ($msg =~ /start/) { my $thread = threads->create(\&thread); } } sub thread { print "Thread started!\n"; sleep 5; threads->detach(); }