Well, most likely your code never gets to the die function. Please state what exactly your code prints out, that may give us more clue as which statement caused the script to hang. I have made a guesses nevertheless: the while loop never exists and the execution never reaches the die function.
Another comment I want to make regarding your code is to use strict and use warnings. Have strict variable declarations to prevent Perl from automatically create variables for you. This will make your code easier to trace, and may save you a lot of debugging time in the future. One of the most comment dangers of not using strict pragma in the code is to misspell a variable name, and Perl creates a new variable with the misspelt name, leaving an inexperienced coder hours to figure out what is wrong with the code.