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 are the foundation of any programming language, so as in Perl. A user can define operators in String as symbols that help to perform specific mathematical and logical computations on operands. These operations are like concatenation, comparison, substitution, etc.
Example:
# Perl program to demonstrate the # Concatenation Operator(.) in String #!/usr/bin/perl # Input first string $first_string = "Geeks"; # Input second string $second_string = "forGeeks"; # Implement Concatination operator(.) $concat_string = $first_string.$second_string; # displaying concatination string result print "String After Concatenation = $concat_string\n"; |
String After Concatenation = GeeksforGeeks
Some useful operators for String operations in Perl are listed below:
| Operator | Description |
|---|---|
| qw | ‘quote word’ operator is used to extract each element of the given string as it is in an array of elements in single-quote ( ‘ ‘ ) |
| q | Used in place of single quotes. It uses a set of parentheses to surround the string |
| Used in place of double quotes. It uses a set of parentheses to surround the string | |
| y | Translates all characters of SearchList into the corresponding characters of ReplacementList |
| tr | Similar to ‘y’ operator it translates all characters of SearchList into the corresponding characters of ReplacementList |
| eq | Used to check if the string to its left is stringwise equal to the string to its right |
| ne | Used to check if the string to its left is stringwise not equal to the string to its right |
| le | Used to check if the string to its left is stringwise less than or equal to the string to its right |
| ge | Used to check if the string to its left is stringwise greater than or equal to the string to its right |
| lt | Used to check if the string to its left is stringwise less than the string to its right |
| gt | Used to check if the string to its left is stringwise greater than the string to its right |
| cmp | Used to compare if the two strings placed left and right to this operator are equal or less than the other |
| substitution operator(s) | Used to substitute a text of the string with some pattern specified by the user |
| matching operator(m) | Used to match a pattern within the given text |
Recommended Posts:
- Perl | String Operators
- Perl | Operators | Set - 2
- Perl | Operators | Set - 1
- Perl | File Test Operators
- Perl | Operators in Regular Expression
- Perl | Useful String functions
- Perl | Extract IP Address from a String using Regex
- Perl | Automatic String to Number Conversion or Casting
- Perl | String functions (length, lc, uc, index, rindex)
- Perl | Basic Syntax of a Perl Program
- Perl Tutorial - Learn Perl With Examples
- Perl vs C/C++
- Perl | cmp Operator
- Perl | Arrays
- Perl | hex Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


