Hi farang,The mySort routine looks like it's not doing it's job properly or efficiently..
Though, I don't know how the OP wants his/her data sorted, but really there is no need for the mySort subroutine. Because, all that that subroutine is doing can be done in a sort block like so:

I don't know how the OP wants his/her data sorted, but really there is no need for the mySort subroutine. Because, all that that subroutine is doing can be done in a sort block...

Yes, you are right, but I guess that Farang wanted to offer a fix while changing as little as possible from the original code. It is often a dilemma for me (here and on other forums) when I see a clear coding error as well as a number of more or less clumsy or suboptimal things around: should we just give the bug fix to make the program work, toi solve the OP's immediate problem, or should we try to refactor the whole shebang. Sometimes, when I have time, I take the trouble of saying something like this: "your error is there, on this line of code, this is what you need to fix; but, BTW, I would think that it would also be better to (follow the following best practices | use a hash instead of an array (or an array instead of a hash) | work the algorithm the other way around | use the following (cleaner|more robust|faster) syntax | use strict and use warnings | use Perlish loops rather than C-style loops | use tr/// instead of s///g | use index instead of a regex | use map and grep instead of foreach (or foreach instead of map and grep) | whatever | etc.). But I don't always have time and I don't always do it.

Really, I don't know how you wanted your hash sorted but I guess you would like to sort using "keys" since, your values from your OP are "kind" of sorted, following the numbers on the names like UEH1_system_ip, UEH11_system_ip,.. etc.The following shows one way of doing it:

I, too, do not understand very well what Rahul Gupta ultimately wants to achieve, but insofar as a numeric-ascending sort of the values of a hash according to a sub-string of decimal digits within each value is concerned, a number of useful answers have been given.

A couple of intersting approaches have been touched on briefly or not at all: our old, work-horse friend the Schwartzian Transform (ST) exemplified by 2teez, and our exciting new friend the Guttman-Rosler Transform (GRT). Both of these techniques are thoroughly discussed in A Fresh Look at Efficient Perl Sorting. The advantage of GRT is that it uses no explicit sort-block at all, but depends on the default, hence fastest, lexicographic-ascending sort ordering of sort. (Update: Well, I'm assuming the implicit sort code has been optimized up the wazoo, so nothing you could do in an explicit block, with its inherent call overhead, could be faster.)

In the following examples, the map { dd $_; $_; }
and map { print qq{=$_=}; $_; }
expressions are intended to show what is being fed to the sort built-in. Do not include them in production code.

I think that I see the problem. Ordinarily, you would be able to iterate over something like foreach ( sort keys(%IP_store) ) ..., but IP-address strings of varying lengths won’t sort correctly as strings.

The sort verb does allow for a subroutine to be specified, which must return a value that is less than, equal or greater than zero as appropriate, so we do have the mechanism by which to sort the strings the way we want: as a left-to-right hierarchical collection of four integers. So, let’s define a separatesub to do this ... something along these (untested) lines:

The split built-in function does not use single-quotes around a /PATTERN/ argument to 'meta-quote' the argument: the '.' in the above really is trying to split on "any character except newline". Use '\.' to split on a literal period.

Excellent point. Thank you. I have updated the post accordingly. But, even so, my post consisted of extemporaneous coding. I did not separately test it to see if it would actually run. I made it only as an illustration of the essential idea, “implementation left as an exercise to the reader.”

Ada Lovelace for the palindrome
Albert Einstein for having smelly feet
Alfred Nobel for his contribution to battlefield science
Burkhard Heim for providing the missing link between science and mysticism
Claude Shannnon for riding a unicycle at night at MIT
Donald Knuth for being such a great organist
Edward Teller for being the template for Dr. Strangelove
Edwin Hubble for pretending to be a pipe-smoking English gentleman
Erwin Schrödinger for cruelty to cats
Hedy Lamarr for weaponizing pianos
Hugh Everett for immortality, especially for cats
Isaac Newton for his occult studies
Kikunae Ikeda for discovering the secrets of soy sauce
Larry Wall for his website
Louis Camille Maillard for discovering why steaks taste good
Marie Curie for the shiny stuff
Nikola Tesla for the cool cars
Paul Dirac for speaking one word per hour when socializing
Richard Feynman for his bongo skills
Robert Oppenheimer for his in-depth knowledge of the Bhagavad Gita
Rusi P Taleyarkhan for Cold Fusion
Sigmund Freud for his Ménage ā trois
Theodor W Adorno for his contribution to the reception of jazz
Wilhelm Röntgen for the foundations of body scanners
Yulii Borisovich Khariton for the Tsar Bomba
Other (please explain why)