use strict; my @all = qw(bin client server all then); my @some = qw(bin client server); #user defined elements my %h; my @c; my $flag; @h{@some} = ( ); # Elements that exist in both arrays exists($h{$_}) and push @c, $_ for @all; if (scalar(@c) == 3) { print "set flag"; $flag = 1; }