If you:
opendir(ims, ...
your dir handle is "ims", as in 'readdir ims'. The
grep is to remove unix files . and .. the current and
parent dir links. readdir returns just the
filenames, not the whole path, so your chdir will work, but
so should his prepend of the path, as in (perldoc -f readdir):
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
@dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR);
closedir DIR;
a