my %temphash = map { $_ => 1 } @arrayA; my @inBbutnotA = grep { !$temphash{ $_ } } @arrayB;