use Sort::Key::IPv4 qw(ipv4sort); my @ip = qw(192.168.1.1 10.0.0.1 127.0.0.1 ...); my @sorted = ipv4sort @ip;