in reply to File Manipulation

If your file is as nicely ordered as the sample you have shown, you probably don't even need any data structure but can print as you read the lines. Something like this:

use strict; use warnings; my $line; while (<DATA>) { chomp; if (/\[(server\d+)\]/) { print $line, "\n" if defined $line; $line = $1 . ": "; } else { $line .= $_; $line .= ','; } } print $line, "\n"; __DATA__ [server1] /tmp/location1/file.log /tmp/location2/file.log [server2] /usr/loc1/file.log /usr/loc2/file.log [server3] /citrix/dir3/file.log

Output:

$ perl serv.pl server1: /tmp/location1/file.log,/tmp/location2/file.log, server2: /usr/loc1/file.log,/usr/loc2/file.log, server3: /citrix/dir3/file.log,