use strict; use warnings; my @big = qw(a b c d e f g h i); my @small = qw(f c d g); my %small; $small{$_}=1 for @small; my @keys_wanted = @small; foreach ( @big ) { push @keys_wanted, $_ unless $small{$_}; } print "@keys_wanted";