use strict; use warnings; opendir my $dh, $new_dir or die "Cannot open directory"; my @GPS = grep { -f "$new_dir/$_" } readdir($dh); closedir $dh;