in reply to How can I opendir, replace all files containing a space with .?

In addition to what's been said already:

Your code looks like you try to replace *any* number of spaces by *one* dot.
If you want to replace one or more spaces by one dot, tr/ /./ will not work.
You have to use s/ +/./g