sub compare_arrays { my ($first, $second) = @_; my %found; my @tmp; for my $elm (@$first) { if(defined($elm) && grep{defined($_) && $elm eq $_}@$second && !$found{$elm}) { push(@tmp,$elm); $found{$elm}++; } } return @tmp; }