use File::Basename; my $dir = dirname($path); $dir .= '/*'; # Note: if the result of dirname already has the slash, you only need to add the * while (glob $dir) { # this will loop through files in that directory, putting each filename in $_ }