Perl escape sequences: Newline, tab, and other special characters

I won't say that this is a complete list, but I think this is a list of the most popular backslash characters (also known as escape sequences) that can be used in Perl strings:

Character Sequence What it Matches
\a Alert/alarm/bell
\b Backspace
\D A non-digit
\e ESC character
\f Form feed
\n Newline character
\r Carriage return
\cC <Ctrl>C
\t Tab

Perl newline and tab examples

You can use these "special" characters (such as the [Tab] character) by putting them inside of Perl strings, like this:

print "Here is a tab\t";
print "Here is a form feed\f";
print "Finally, here's a bell a newline\a\n";

As a practical matter, it's very common to print Perl newline characters, and it's relatively common to print tab characters. I don't use most of the other escape characters too often, but it's nice to know they're there when you need them.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.