my @a = qw(3 00:0B:3B:42:64:E9 5[9[@+Q6cKgB 06:04:51 1 00:0B:3B:42:65:E6 R1Q!Sw#dVdH= 06:04:51 2 00:0B:3B:42:65:F0 R1Q!Sw#dVdH= 06:04:51 4 00:0B:3B:42:64:5B 5[9[@+Q6cKgB 06:04:51 ); my @b; for (my $i = 0; $i <= $#a; $i += 4) { push @b, join " ", @a[map {$_ + $i} (0 .. 3)]; } print "$_\n" for sort @b