if($motive1 eq $motive2) { my @list=@{$match{$motive1}}; for my $pos1 (0 .. $#list-1) { for my $pos2 ($pos1+1 .. $#list) { push(@found,[$motive1,$motive1,$list[$pos1],$list[$pos2]]); } } } else { for my $line1 (@{$match{$motive1}) { for my $line2 (@{$match{$motive2}}) { push(@found,[$motive1,$motive2,$line1,$line2]); } } }