#!/usr/bin/env perl use warnings; use 5.014; use Algorithm::Loops qw/NestedLoops/; use Benchmark qw/:all/; my @SKU = (1..5); my @shirt = qw/T S L H/; my @size = qw/S M L XL 2X/; my @col = qw/BLU GRN WHT BLK/; say scalar algorithm_loops(); say scalar nested_loops(); say scalar do_glob(); cmpthese(-10, { 'Algorithm::Loops' => \&algorithm_loops, 'Nested loops' => \&nested_loops, 'glob' => \&do_glob, }); sub algorithm_loops { return NestedLoops([ \@SKU, \@shirt, \@size, \@col ], sub { 'SKU' . join '', @_ }); } sub nested_loops { my @r; for my $sku (@SKU) { for my $shirt (@shirt) { for my $size (@size) { for my $col (@col) { push @r, 'SKU'.$sku.$shirt.$size.$col; } } } } return @r; } sub do_glob { () = glob 'SKU{'.join(',',@SKU).'}{'. join(',',@shirt).'}{'. join(',',@size).'}{'. join(',',@col).'}'; }