in reply to Re: thanks
in thread thanks, i'm new. rtfm right? :)

The assignment of $_ to $j seems redundant to me. Just write it like this:
foreach (@d) { $template=/^.*\.[^.]+/ if(/$count/); }
$_ is already filled with whatever is in @d...