my %count = (); my @tableused = (); foreach $W (@tableList,@fileList){ $count{$W}++ }; foreach $elem (keys %count) { push @tableused, $elem if $count{$elem} > 1; }