my @matrix; while (my $file = glob "*.db") { tie my %hash, "DB_File", $file, O_RDONLY, 0644 or warn("Could not read $file: $!") and next; # presize the array the first time @matrix = map [], 1 .. keys %hash unless @matrix; my $i = 0; for (sort keys %hash) { push @{ $matrix[$i++] }, $hash{$_}; } }