#!/usr/bin/perl -p # change all "foo.bar.com" style names in the input stream # into "foo.bar.com [204.148.40.9]" (or whatever) instead use Socket; # load inet_addr s{ # substitute this: ( # capture the hostname in $1 (?: # these parens for grouping only (?! [-_] ) # next mustn't be underbar or dash [\w-] + # one or more alphanums or dashes \. # and the domain dot ) + # now repeat that whole thing a bunch of times (?= [a-z] ) # next must be a letter [\w-] + # one or more alphanums or dashes ) # end of $1 capture }{ # replace with this: "$1 " . # the original bit, plus a space ( ($addr = gethostbyname($1)) # if we get an addr ? "[" . inet_ntoa($addr) . "]" # format it : "[???]" # else mark dubious ) }gexi; # /g for global # /e for execute # /x for nice formatting # /i so the a-z is case insensitive