in reply to looping efficiency

(s)?printf will do what you want without difficulty–

perl -e 'printf "%04d\n", $_ for 0 .. 9999'

Update, swapped the 1 for a 0.