my @files; if (-d $x_file) { # $x_file is a directory, not a file @files = glob "$x_file/*xml"; } elsif ($x_file =~ /xml$/ and -e $x_file){ # $x_file is an xml-file, and we have access to it push @files, $x_file; } else { die("can't make sense out xml-directory or xml-file $x_file"); }