Please review the basic documentation that accompanies Perl. Notably, the perlfunc document explains what the _X function does. One of its forms tests to see if something is a directory, which should be what you need.
I also highly recommend the introductory book Learning Perl.