Perl | Useful String functions Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report A string in Perl is a scalar variable and start with a ($) sign and it can contain alphabets, numbers, special characters. The string can consist of a single word, a group of words or a multi-line paragraph. The String is defined by the user within a single quote (‘) or double quote (“). Perl provides various functions to manipulate the string like any other programming language. Example: Perl # Perl program to demonstrate # string length function # string my $s = "geeksforgeeks"; # using length function & # displaying length print("Length: ", length($s)); # Converting to Uppercase print("\nTo Upper Case: "); print(uc($s), "\n"); Output: Length: 13 To Upper Case: GEEKSFORGEEKS Some string functions of Perl are as follows: Function Description chomp() Used to remove the last trailing newline from the input string length() Finds length (number of characters) of a given string, or $_ if not specified substr() Returns a substring out of the string passed to the function starting from a given index up to the length specified uc() Returns the string passed to it after converting it into uppercase ucfirst() Returns the string VAR or $_ after converting the First character to uppercase lc() Returns a lowercased version of VAR, or $_ if VAR is omitted lcfirst() Returns the string VAR or $_ after converting the First character to lowercase chr() Returns a string representing a character whose Unicode code point is an integer chop() Returns a string representing a character whose Unicode code point is an integer index() Returns the position of the first occurrence of given substring (or pattern) in a string (or text) rindex() Returns the position of the last occurrence of the substring (or pattern) in the string (or text) sprintf() Uses Format provided by the user to return the formatted string with the use of the values in the list ord() Returns the ASCII value of the first character of a string quotemeta() It escapes all meta-characters in the value passed to it as parameter split() Used to split or cut a string into smaller sections or pieces Comment More infoAdvertise with us Next Article Perl | Useful Array functions A Abhinav96 Follow Improve Article Tags : Perl Perl-String Perl-function Perl-String-Functions Similar Reads Perl | Useful String Operators A string in Perl is a scalar variable and start with a ($) sign and it can contain alphabets, numbers, special characters. The string can consist of a single word, a group of words or a multi-line paragraph. The String is defined by the user within a single quote (â) or double quote (â). Operators a 3 min read Perl | Useful Hash functions A hash is a set of key-value pairs. Perl stores elements of a hash such that it searches for the values based on its keys. Perl provides various functions to perform operations on Hashes, such as to return values of the hash, to delete elements from a hash, etc. Example: Perl #!/usr/bin/perl # Initi 2 min read Perl | sprintf() Function sprintf() function in Perl uses Format provided by the user to return the formatted string with the use of the values in the list. This function is identical to printf but it returns the formatted string instead of printing it. Syntax: sprintf Format, List Returns: a formatted scalar string Example 1 min read Perl | Useful Array functions In Perl, array is a special type of variable. The array is used to store the list of values and each object of the list is termed as an element. Elements can either be a number, string, or any type of scalar data including another variable. Array in Perl provides various inbuilt functions to perform 2 min read Perl | List Functions A list in Perl is a collection of scalar values. We can access the elements of a list using indexes. Index starts with 0 (0th index refers to the first element of the list). We use parenthesis and comma operators to construct a list. In Perl, scalar variables start with a $ symbol whereas list varia 4 min read Perl | Useful File-handling functions Perl was originally developed for the text processing like extracting the required information from a specified text file and for converting the text file into a different form. These operations can be performed by the use of various inbuilt file functions. Example: Perl #!/usr/bin/perl # Opening a 2 min read Like