Your grep should have !/^\.\.?$/ rather than !/\.\.?/. Your pattern will match any filename with a dot in it, which results in any file with a dot in its name will not be in @imss, which is probably why your files aren't being deleted. /^\.\.?$/ will match only '.' and '..' which I believe is what you are trying to do.