undef $/; $file = <>; s/\s*\n/,/s; #catches spaces as well. print; #### chomp; print; print ',' while ( <> );