perl -ple'$\ = $.%5 ? ";" : $/' infile > outfile #### perl -i.bak -ple'$\ = $.%5 ? ";" : $/' file #### while ( ) { chomp; print $_, $.%5 ? ";" : $/; }