Directory BFS traversal, perl implementation