# untested my %foo = map { split /,/, $_, 2 } @arr2; my @arr3 = map { exists $foo{$_} ? $foo{$_} : () } @arr1;