for (@fuente) { my @parts = split /\|/; ++$seen{$parts[1]} = $_; } for (@fuente2) { my @parts = split /\|/; if ($seen{$parts[2]}) { print $seen{$parts[1]}; # That's the matching line from @fuente print; # That prints the line from @fuente2 } }