How to concatenate two or more strings in Perl using the period

Overview

Strings in Perl can be concatenated using the period ., which is an operator we can use to combine two or more strings.

Syntax

string1.string2.string3.stringN
The syntax for concatenating two or more strings in Perl

Parameters

string1, string2, string3,...,stringN: These are strings we want to join/concatenate.

Return value

A new string is returned which is a combination of all the strings concatenated.

Example

# create some strings
$a = "Welcome";
$b = " to";
$c = "Nice to have you here!";
# concatenate all strings
$d = $a.$b." Edpresso! ".$c;
# print the concatenated string
print $d;we

Explanation

  • Lines 2-4: We create some strings.
  • Line 7: We concatenate the strings using the period operator ..
  • Line 10: We print the concatenated string to the console.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources