in reply to sub functions return array's

The biggest bug I see is that you are calling readdir multiple times in list context, but it will only return the directory once. If you want to iterate through it multiple times you should call it once and store that in an array. The second biggest potential cause of problems is that you are returning a reference to an array rather than the array directly, which could be a problem depending on how you are calling it.

However that said, virtually every line has "room for improvement". Here is a list of specifics:

Here is a rewritten version of your function. I have left your naming convention and indentation style alone because they are reasonable if different from my usual:
sub getfiles { my ($dirName, @patterns) = @_; opendir(my $dir, $dirName) or die "Can't open '$dirName': $!"; my @return; for my $file (readdir($dir)) { for my $pattern (@ARGV) { if ($file =~ /$pattern/) { push @return, $file; # This avoids having the file in the result twice last; } } } return @return; }
And then you call it like this:
my @uploads = getfiles($logSite, @ARGV);