use File::Slurp; for my $file (grep { -f } read_dir($dir_to_open)) { # I want to delete the files }