[server1] /tmp/location1/file.log /tmp/location2/file.log [server2] /usr/loc1/file.log /usr/loc2/file.log [server3] /citrix/dir3/file.log #### server1:/tmp/location1/file.log,tmp/location2/file.log server2:/usr/loc1/file.log,/usr/loc2/file.log server3:/citrix/dir3/file.log #### #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @lines; my @data; open (my $file, '<', 'log') or die $!; while (my $line = <$file>) { if ($line =~ /\[(.*)\]/) { push (@lines, $1); next; } if ($line =~ /(\/.*)/) { push (@data, $1); next; } } my $val = join(",",@data); close $file; foreach(@lines){ print "$_:$val\n";