You may be correct, but the statement that you see the last print does
NOT offer any assurances that
Temp.pl actually ends: all you know for sure based on what you've told us is that
Temp.pl runs thru the last print statement.
Is "the last print statement contained in it" the very last code in the script?
As to your question about how to end the while loop: you haven't shown us the code. Guessing on a fix for unknown code is not worth our time or yours.
If you didn't program your executable by toggling in binary, it wasn't really programming!