foreach (@data1) { $hist{$_}++ for $_; } my @uni = keys %hist; print "@uni\n";