my @x = (4, 4, 2); my $pref = 'XX'; my @y = map {my $chunk=$_; map{sprintf("$pref%02d:",$chunk).$_}1..$x[$chunk-1]}1..@x;