my $dir = "/home/gaurav/Documents"; opendir my $dh, $dir or die "Couldn't open $dir: $!"; chdir($dir); while (readdir $dh) { next if $_ eq "." or $_ eq ".." ; print $_, " " x (30 - length($_)); # ...do file tests against $_ here }