It seems you don't need any communication from the ftp downloader back to the query/main program and more than one ftp download might get started simultaneously without any dire consequences (except maybe if it is the same file to download. If that's a problem, downloader.pl might use a lockfile or download to a randomly generated name and do a rename after download is complete). So the easiest solution is to start a separate program which does the ftp download and gets its data simply over the command line:
while($query=getnewquery())
#database query
...
$filename= ...
# start the download
system("downloader.pl $filename &") or print "failure to start downl
+oader.pl\n";
}
The '&' starts the downloader.pl program in the background so it is executed in parallel. Depending on the ftp download downloader.pl might be substituted with the actual ftp command.