#!/usr/bin/perl # http://perlmonks.org/?node_id=1211055 use strict; use warnings; use Data::Dump 'pp'; my @a = (1, 2, 3); my @b = ("a", "b"); my @bc = map [ split // ], glob +('{' . join(',', @b) . '}') x @a; my @c = map { my $t = $_; [ map [ $_, $t->[$_-1] ], 1..@a ] } @bc; pp @c;