opendir(MYDIR,"dir") or die "$!\n"; @txtfiles = grep { /\.txt$/ } readdir MYDIR; closedir MYDIR;