in reply to Matching problem

Array is not going to help you much. The right data structure here is hash:
#!/usr/bin/perl use warnings; use strict; my %players; while (<DATA>) { my ($team, $left, $right) = m{(.+)=(.+?) */ *(.+)}; my @lefts = split / *, */, $left; my @rights = split / *, */, $right; $players{$_}{left} = $team for @lefts; $players{$_}{right} = $team for @rights; } for my $player (keys %players) { if (2 == grep exists $players{$player}{$_}, qw/left right/) { print "$player IS IN $players{$player}{right} AND", " $players{$player}{left}\n"; } } __DATA__ Team1=Joe / Phil , Amenda Team2=James / Pam, Joe Team3=Carmen , Lisa / James Team4=Don , Phil / Carmen Team5=Uri , Kate / Don

As you can see, it assigns each player his/her left and right team, and only lists the players with both teams assigned. It does not check, though, whether a player is not assigned more than one team on the same side.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ