Your outer for loop is doing nothing of any consequence. Your inner for loop is substituting all occurrences of NUM in @dn, leaving no occurrences left for your subsequent iterations of your outer loop.
Perhaps you need to re-investigate your logic?
Comment on Re: Re: regular expressions and substituting in variables.