in reply to How do i sort a hash or array?

You have chosen a really bad representation for sorting.

You could transform your data to an array of hashes instead:

my @persons = { firstname => 'name1', lastname => 'lname1', city => 'city1', }, { firstname => 'name2', lastname => 'lname2', city => 'city2', }, ... );

And then sort with sort { $a->{firstname} cmp $b->{firstname} } @persons.