There are several way for this to be done. Since the entire process is in Perl, an presumably in Perl, there are forking, and threads.
Threads are somewhat (very) experimental and should not be used for production work, so,
.
function, and maybe take a look at super search, or the book "Network Programming with Perl".