use strict; use constant DEBUG => 2; my $team; my $player; my %teamAccts; my %teamAcctsUniq; my $teamAccts; my $teamAcctsUniq; while () { chomp; if ( (/^T:/) ){ $team = (split /:/) [1]; } if ( (/^P:/) ) { $player = (split /:/) [1]; push( @{$teamAccts{$team}}, $player); } } my %seen; @$teamAcctsUniq = grep { ! $seen{$_->{player}}++ } @$teamAccts; #print Dumper(\%teamAccts); print Dumper(\%teamAcctsUniq); __DATA__ T:REDS P:GRIFFEY P:GRIFFEY P:PEREZ P:ROSE P:BENCH T:PHILLIES P:ROSE P:ROSE T:MARINERS P:GRIFFEY P:PEREZ