Open In App
Related Articles

Perl | join() Function

Improve Article
Save Article
Like Article

join() function in Perl combines the elements of LIST into a single string using the value of VAR to separate each element. It is effectively the opposite of split.

Note that VAR is only placed between pairs of elements in the LIST; it will not be placed either before the first element or after the last element of the string. Supply an empty string rather than undef, to join together strings without a separator.

Syntax: join(VAR, LIST)


  • VAR : Separator to be placed between list elements.
  • LIST : LIST to be converted into String.

Return: Returns the joined string

Example 1:

# Joining string with a separator
$string = join( "-", "Geeks", "for", "Geeks" );
print"Joined String is $string\n";
# Joining string without a separator
$string = join( "", "Geeks", "for", "Geeks" );
print"Joined String is $string\n";


Joined String is Geeks-for-Geeks
Joined String is GeeksforGeeks

Example 2:

# Joining string with '~' separator
$string = join( "~", "Geeks", "for", "Geeks" );
print"Joined String is $string\n";
# Joining string with '***' separator
$string = join( "***", "Geeks", "for", "Geeks" );
print"Joined String is $string\n";

Output :

Joined String is Geeks~for~Geeks
Joined String is Geeks***for***Geeks
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 25 Jun, 2019
Like Article
Save Article
Similar Reads