#!/usr/bin/perl use strict; use warnings; use Socket qw /inet_aton inet_ntoa/; my %ip_store = ( "11.0.0.1" => "UEH1_system_ip", "11.0.0.11" => "UEH11_system_ip", "11.0.0.3" => "UEH25_system_ip", "11.0.0.25" => "UEH111_system_ip" ); my @sorted = map {inet_ntoa $_} sort map {inet_aton $_} keys %ip_store; foreach my $ip (@sorted) { print "$ip\n"; print "System_ip = '$ip_store{$ip}' \n"; } #### C:\Old_Data\perlp>perl t9.pl 11.0.0.1 System_ip = 'UEH1_system_ip' 11.0.0.3 System_ip = 'UEH25_system_ip' 11.0.0.11 System_ip = 'UEH11_system_ip' 11.0.0.25 System_ip = 'UEH111_system_ip'