#!/usr/bin/perl -w my $output = ''; while(){ if(/\:$/){$output .= qq|\n$_|} else {chomp($_);$output .= $_ . q|,|}; } print $output; 1; __DATA__ heading1: this is a tst heading2: this is another test The result is: heading1: this,is,a,tst, heading2: this,is,another,test, C:\Temp>