Updated: 04/26/2017 by Computer Hope

A newline is a character used to represent the end of a line of text and the beginning of a new line. In programming languages such as C, Java, and Perl, the newline character is represented as a '\n' escape sequence. Below is examples of how the newline could be used in Perl.

# Print "Hello World!" and start a new line with \n
print "Hello World!\n";

#Locate and replace any newlines in the mydata variable
#and replace those newlines with a ** as the separator.
$mydata =~ s/\n/**/g;

In the above code, Perl would first print "Hello World!" and move to the next line. In the second section of the example, the $mydata variable would have all new lines stripped and replaced with "**". Using this type of regular expression can be helpful when you need to parse text with newlines or need to place data with newlines in a single line of text.

Note: A newline is not the same as a carriage return.

CR, LF, Line, Meta-character, Programming terms, White space