http://www.perlmonks.org?node_id=11104616


in reply to The error says the value is uninitialized, but it works anyway

haukex has explained your indexing problem. You can fix it by processing the array backwards. No other change to your code is required. (Of course you should restore the strict and warnings).
foreach $num (reverse 1..$count){

I recommend against using a previously defined lexical variable as a loop variable. It does not make any difference in this script, but it is a bad practice. In the future, you may be tempted to use that variable after the loop has finished and it almost certainly will not contain what you expect. Use the syntax haukex showed.

Bill