in reply to How can I reduce the time taken by wav file to save in /tmp folder

my ($fh, $tmpname) = tempfile("stt_XXXXXX", DIR => $tmpdir, UNLINK => 1);

Ok, you ask for a temp file to be created in a particular directory and for that temp file to be deleted automatically when $fh goes out of scope.

What does @result = checkresponse(); do?
Where are you using the temp filehandle, $fh?

I don't know how big this .wav file is? Downloading the entire file and then processing the entire downloaded file is one thing. Overlapping the start of processing while the download is still going on is a very different matter. I don't see anything here that reflects that level of complexity.

Update: Out of curiosity, why would you specify your own temp dir? Why not use the system provided one? If your program "dies", a useless file may be left in that directory that standard "clean up" utilities will not detect.