use strict; my @files = grep ($_,map -e $_ && $_ , qw(foo foobar bar)); if (@files) { print "there are files\n"; #here @files holds the names of the files print(join(",",@files),"\n"); } else { print "no files\n"; }