my @loop_data = (); my @keys = (); my @values = (); # incidentally, the "my %hash" on the next line should be just "%hash" while ((my $key, my $value) = each my %hash) { push(@keys, $key); push(@values, $value); } while (@keys and @values) { my %row_data; $row_data{KEY} = shift @keys; $row_data{VALUE} = shift @values; push(@loop_data, \%row_data); }