in reply to Getting first and last element value of a hash loop

I do not know how your %ERROR1 hash gets populated and whether it is also used for other purposes, but you might consider using a HoH...HoA rather than a HoH...HoH, i.e. the 'DAILY' and the 'WARNING 85% FULL' values might be array references instead of hash references, since the values in the most-nested hashes (always 1) seem to be fairly useless.

Depending on where these values are populating from, there would be a high chance of having them sorted in the proper order so that you would not need to do any sort and could just pick up the first and last elements of these arrays.

But of course, this is just a suggestion, you might not have the freedom to change this data structure for other reasons.