... for my $element (@array2) { my ($num, $txt) = split /#/, $element; # extract parts print "$txt = $num\n" if grep $num eq $_, @array1 # use text comparison and print txt part } ...