#!c:\perl\bin\perl -w use strict; # open(NB, "nbt.csv")|| die"Cant open input file nbt.csv"; # NBT.CSV simply contains ip addresses - one per line # as DATA sample does my %stathash = (); while(my $ip = ){ chomp $ip; #put nbtstat results in an array, one line = one element my @nbtstat = split /\n/, `nbtstat -a $ip`; #modify @nbtstat to discard gibberish (if desired) for (@nbtstat){ s/^\s+//g; $_ = substr($_,0,15); s/[^a-z|A-Z|_|0-9|\040]//g; s/\s+$//g; } # remove duplicates from array my %uniq; @nbtstat = grep { ! $uniq{$_} ++ } @nbtstat; $stathash{$ip} = \@nbtstat; } for my $key (keys %stathash){ print "\n$key: \n"; #skip empty elements otherwise print to list /.+/ and print "$_," for @{$stathash{$key}}; } __DATA__ 192.168.0.2 192.168.0.4 192.168.0.5 192.168.0.6