use strict; my @arr = ; map chomp $_, @arr; foreach my $i (0..$#arr){ foreach my $j (0..$#arr){ print "$arr[$i] $arr[$j]\n" if $i != $j; } }