my %map; @map{@l2} = (); my @list = map { exists $map{$_} ? $_ : 'null' } @l1;