First, are you sure your @dir array really has blank lines in it? Is it possible that some of your strings have newlines on the end of them? Try using
to get a full view of the actual contents of your array. If the problem is in fact trailing newlines, then you might want to use
when inserting the strings into your array.