in reply to detached thread not working??
I don't know Perl's threads well enough to solve your problem, I'm afraid. So why am I posting? I noticed piles of print statements in your code. You may want to look at heredoc for better code legibility, particularly the << "EOF" form.