sub getfiles() { opendir DIR,$logSite or die "Unable to open Directory, please try ag +ain"; foreach $pattern (@ARGV) { push (@uploads, grep /$pattern/, readdir(DIR)); } closedir DIR; return \@uploads; } my $aref = &getfiles; print @$aref; # or whatever