use strict; use warnings; my %hash; $hash{col1} = [qw(a b c d e)]; $hash{col2} = [qw(1 2 3 4 5)]; $hash{col3} = [qw(q r s t u)]; # Change this so that the keys of %hash # show up in the order you want them, # in the output. my @keys = sort keys %hash; # Assumes every key of %hash is an # arrayref with the same number of # elements in it. Also note that # this code destroys %hash, as # it goes along. If you don't want # that, make a copy first. print join(",", @keys), "\n"; my $ref_key = $keys[0]; while (@{ $hash{$ref_key} }) { my @line; for my $key (@keys) { push @line, shift(@{ $hash{$key} }); } print join(",", @line), "\n"; }