in reply to PM and references

for(my $i=0;$i<=$top;$i++) { $DATA=$reg->[$I];
you are using $i and $I, which are different variables .. are you sure you want this?
Rata