in reply to Generate Matrix in perl

Set::CrossProduct should do what you want, if I understood your question correctly.