It sounds like you are trying to produce a linked list in
Perl. For most purposes linked lists are not necessary
because native arrays are efficient enough. However
inserting in the middle is still O(n). So if you
need more complex data structures then you might want to
take a look at how
Dominus implemented
BTrees in Perl.
For production code I would just use a real database or
else use DB_File to tie a hash to an efficient
BTree implementation...