#! perl -slw use strict; open IN, ' ); close IN; @links = grep m[^\w+://], @links; # remove relative urls. my @sorted = map{ substr($_, 1+index($_, $;)); } sort map{ m[\w+://([^/]+)/]; join( '.', reverse split /\./, $1 ) . $; . $_; } @links; print for @sorted;