#!perl use warnings; use strict; my $dir = '/home/sites/$arg1/users'; opendir DIR, $dir or die "Cannot opendir $dir:$!\n"; my @users = grep { -d "$dir/$_" and not /^\.{1,2}$/} readdir DIR; closedir DIR; # do whatever you want with @users print join "\n",@users;