for my $elem ( @a ){ push @z, $_ = ( first { $elem eq $_ } @b ) ? '+' : '-'; }