in reply to sorting hash of hashes

Your initial data structure appears not to be a hash (despite the initial % sigil), but a hash reference, so that looping on the keys will fail.

Is this data structure something that you built yourself, or do you get it from another program or a subroutine/module call that you have not shown?

If you're building it yourself, then change it to something like:

%update = ( '2'=>{ '25' => { 'i' => 5000000, 'o' => 5000000 }, '4' => { 'o' => 5000000, 'i' => 5000000 } } );
(Parens instead of curlies for the external delimiters.)

If you're getting that hash ref data structure from somewhere else (e.g. another program or another part of your program), then you probably need to change your foreach loops to use a hashref instead of a hash. For example, change the foreach my $i (keys %update) line to something that uses an hash ref rather than a hash, for example, assuming your data hashref is $update, something like:

foreach my $i (keys %$update) { #...