my $product = iter_prod( $abcees, $xyzees ); while (defined (my $vals = $product->())) { my @vars = @$vals; print "Got vars: @vars\n"; # do real work here } # Got vars: a x # Got vars: a y # Got vars: a z # Got vars: b x # Got vars: b y # Got vars: b z # Got vars: c x # Got vars: c y # Got vars: c z