opendir THEDIR, "$ipath"; for $file (grep (/$str/, readdir THEDIR)) { # Do the work } closedir THEDIR;