A simple solution would be to pack the IPs as if you were
passing them to the socket routines. In this format the IP will be 4 bytes, where each byte is the numbers from the IP
use Socket;
@sortedKeys = map { inet_ntoa($_) }
sort map { inet_aton($_) }
keys %hash;