use strict; my @p_types = qw( pam php kph ); my @c_types = qw( cam c1 c2 ); my @true = qw(pam c2); #@true = qw(cam c2); #@true = q(pam php); # intermediate hash my %true = map { ( $_ => 1 ) } @true; if ( grep( $true{$_}, @p_types ) && grep( $true{$_}, @c_types ) ) { print "Opt A: Array consists of elements from both arrays\n"; } # "pure" grep if (( grep { my $type = $_; grep( $_ eq $type, @true ) } @p_types ) && (grep { my $type = $_; grep( $_ eq $type, @true ) } @c_types ) ) { print "Opt B: Array consists of elements from both arrays\n"; }