sub blah { @array = match_files(\@array, \%hash); print "@array \n"; } sub match_files { @files = (); my($array, $hash) = @_; my(@array) = @$array; my(%hash) = %$hash; foreach $ary_element (@array) { foreach $hash_key( keys ( %hash )) { # do my comparison here } # if i get a match print "$ary_element\n"; # prints defined value push (@files, $ary_element); return @files; } }