Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

concatenate
strings
perl
communitycreator

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

okwudili onyejiaku

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 
Concatenating strings in Perl

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.

RELATED TAGS

concatenate
strings
perl
communitycreator
RELATED COURSES

View all Courses

Keep Exploring