in reply to READDIR: files printed twice in the directory ?

It seems that traversing tree structures has proven to be harder that it looks :)

Is there any reason not to use File::Find? Code reuse has been proven to be fruitful.

As for your code, in the way it is presented, it is very hard to say anything concrete. You do not show the context of your function call (i.e. what the actual call looks like, what are the arguments...). The function itself uses global variables and there is no way to say how those are populated. Please look at How (Not) To Ask A Question for more comments on how to post your questions here. However, if I were to guess about the root cause of your problem, I would take a look at your @inputdir global array to see if it contains duplicate entries. Again, this is a shot in the dark!

BR