my $dir = '.'; opendir(my $dh, $dir) or die "Could not open $dir because $!\n; while(readdir($dh)){ # do stuff to $_ } closedir($dh);