in reply to how do I remember the trailing /

Your problem is (apparently) that the output of ls is different between your console shell session and your Perl script. The most likely reason for this is that the ls you are calling in your shell session is an alias set in one of your (or your system's) login scripts. I don't know what system you're using, but on my Linux box, if I type:

$ which ls alias ls='ls --color=auto -B' /bin/ls
so you see that my console session runs ls with some options. However, you don't generally inherit aliases. So what you want to do is either to run ls with the -p option as Hofmator suggested, or to use stat or -d to find out whether the file is a directory.