in reply to Sort in IP in 2 lines.

A regex to match (optionally zero padded, decimal) dotted-quad IPs is fairly involved.
#!/usr/bin/perl -w use strict; my $octet = q[0?\d\d?|1\d\d?|2[0-4]\d?|25[0-5]|2[6-9]]; # MUST BE CONS +TRAINED my $ip = q[(?<!\d\.)] . join(q[\.], ( "($octet)" ) x 4) . q[(?!\.\d)]; my $rx = qr/$ip/;
Even that isn't perfect(!), but it's much closer. To sort by IP, you should capture the octets and feed them to pack "C4", yielding a string that can be used for ASCIIbetical sorting. This is a basically a task that naturally lends itself to a GRT:
my @line; while(<>) { push @line, pack("C5", (@octet = /$rx/ ? 1, @octet : (0) x 5 ) ) . + $_; } print map substr($_, 5), sort @line;
Note I'm using C5 here to be able to distinguish lines with no IP at all from those with 0.0.0.0.

Makeshifts last the longest.