use warnings; use strict; my @arr = qw (J K L M N O J K); my %done; while (@arr) { my $str = join ' - ', splice @arr, 0, 2; next if exists $done{$str}; $done{$str}++; print "$str\n"; }