in reply to My data structure needs too much memory!

$hash{$a}{$b}{$c}{$d} = $d;
If you really do just need to store small numbers (eg in the range 0..7) using only small contiguous numeric indicies, then you can store the number with minimum memory using vec(), at the cost of slower access:
$hash{$a}{$b}{$c}{$d} = $d; # before vec($data, $a*4000*10*8 + $b*10*8 + $c*8 + $d, 8) = $d; # after
That would use approx 60 Mb rather than the several Gb before. My example vec line assumes you use indexes from 0 rather than 1.