use strict; while (){ chomp; # Get rid of the EOL print "$_ "; # Don't forget to add a space or the records will run into each other! print "\n" unless $_; # Print an EOL if the line is empty (=record separator) } __DATA__ Start: afadffdafadf stuff stuff stuff stuff Close: xzy Start: afadffdafadf stuff stuff stuff stuff Close: xzy Start: afadffdafadf stuff stuff stuff stuff Close: xzy