#!/usr/bin/perl use strict; use warnings; my @PairLines; my %Pairs; my %PairsOf; @PairLines = ; chomp(@PairLines); foreach my $Line (@PairLines) { chomp $Line; $Line =~ s/^\s*//; $Line =~ s/\s*$//; if ($Line =~ m/^Pairing Start (.*)\s+(.*).*/) { my $Person1 = $1; my $Person2 = $2; $Pairs{$Person1} = $Person1 if (!defined($Pairs{$Person1})); $Pairs{$Person2} = $Person2 if (!defined($Pairs{$Person2})); $PairsOf{$Person1} = $PairsOf{$Person1} . " " . $Person2; $PairsOf{$Person2} = $PairsOf{$Person2} . " " . $Person1; } } __DATA__ Pairing Start Person1 Person2 Pairing End ########################################### Pairing Start Person1 Person3 Pairing End ########################################### Pairing Start Person1 Person4 Pairing End ########################################### Pairing Start Person1 Person5 Pairing End ########################################### Pairing Start Person2 Person3 Pairing End