opendir(DIR, system('pwd'));
Sorry, that should be: opendir(DIR, `pwd`); ` returns output. system() does not.