use strict; my @ips = ( "1.2.3.4", "1.2.3.5", "1.2.3.3", "2.2.3.4", "1.0.2.3"); @ips = map {$_->[1]} sort {$a->[0] cmp $b->[0]} map { [ join(".", map {sprintf "%03d", $_} split('\.', $_) ), $_ ] } @ips; print join "\n", @ips; __OUTPUT__ 1.0.2.3 1.2.3.3 1.2.3.4 1.2.3.5 2.2.3.4