my @computers = grep { /\$$/ } @users; s/\$$// foreach @computers; # remove trailing $ @computers = join("\n",@computers); #### @addr = gethostbyname($hostname); # note: an array now splice(@addr, 0, 4); # get rid of other stuff foreach (@addr) { print OUT join('.', unpack('C4', $_)), "\n"; }