in reply to grep unique values , remove the blank spaces and store it in a variable

The output function adds an extra blank line. We can specify the format, map an array and name the function.
sub print_as_lines { map { print "$_\n" } @_; }
This can not remove all the extra lines, because new lines were added while capturing the data, and before processing. The original line preformats the data for presentation. The function print_as_lines encapsulates the presentation operation.

The program also modifies user input without looking at it first. The following will look before leaping.

my $lanip = $server->{LanIP}; # no change on block entry # oops, this will format for output before processing $lanip .= "\n" unless $lanip =~ /\n$/; # no change if present #oops, did not validate input
The following xml has four blank lines, and the original code will make them five.
<lanIP> 192.168.42.7 </lanIP>
Do you see them all? The text node includes white space by default.
my $lanip = $server->{LanIP}; die "Value Error: not dotted quad notation->($lanip)" unless $lanip =~ + /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/; my $lanip = $1; # now this house is clean
Now you can add another function and wrap the for loop in a function.
sub unique_network { ... for each return @array } sub print_address { print_as_lines @_: } print_address( unique_network($servers) );