in reply to Read all the file path having text document

Why not use File::Find::Rule or similar?

my @files = File::Find::Rule->new() ->file() ->name('*.txt') ->in($path);

If you have a problem with links (symbolic or hard) that point to a parent directory, I don't know if they'll help. What they will do is make your code clearer and save you from reinventing the wheel.