use strict; my @big = qw(a b c d e f g h i); my @small = qw(f c d g); my @keys_wanted = @small; foreach (@big) { my $found = 0; foreach my $already_there (@small) { if ($already_there eq $_) { $found = 1; last; } } if (!$found) { push (@keys_wanted, $_); } } print "@keys_wanted";