use strict; use warnings; my @array = sort {$a <=> $b} qw/ 23 45 12 4 8 7 5/; while (my $item = shift @array) { print "$item $_\n" for @array; }