use strict; my %hash = ( one => [qw(1 2 3 4 5)], two => [qw(a b c d e)], the => [qw(l m n o p)] ); my (@cols, @vals); foreach my $key ( keys %hash ) { push @cols, $key; push @vals, scalar( join ",", @{$hash{$key}} ); } foreach my $val ( @vals ) { print "$val"; print "\n"; } print "\n"; my $statement = 'insert into this (' . (join ",", @cols) . ') values (' . (join ",", @vals) . ')'; print "$statement\n\n";