Search⌘ K

String Operators

Explore how to handle and manipulate strings in Perl using two key operators: concatenation and concatenation assignment. Understand how to join strings effectively and the differences between these operations to enhance your Perl scripting skills.

We'll cover the following...

There are only two string operators:

  • Concatenation (.):
  • Concatenation Assignment (.=)

Concatenation

The most important operation in strings is concatenation. It means joining one string to another. For instance, the concatenation of water and bottle will result in a string water bottle.

Run the code below to see how this is done:

Perl
$a = "water";
$b = " bottle";
$c = $a . $b; # $c => water bottle
print $c;

Concatenation assignment

Concatenation assignment is a slight variation of concatenation where you concatenate (add) one string at the end of another without the need for a third destination string. The difference between concatenation and concatenation assignment is similar to + and +=.

Run the code below to see how this works:

Perl
$a = "Hello";
$a .= " World"; # $a => Hello World
print $a;