Perl | y Operator Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 3 Likes Like Report The y operator in Perl translates all characters of SearchList into the corresponding characters of ReplacementList. Here the SearchList is the given input characters which are to be converted into the corresponding characters given in the ReplacementList. Syntax: y/SearchList/ReplacementList/ Returns: the translated string Example 1: This example uses y operator for translating from lower case to upper case. Perl #!/usr/bin/perl # Initialising some strings $string1 = 'gfg is a computer science portal'; $string2 = 'geeksforgeeks'; # Calling to y function $string1 =~ y/a-z/A-Z/; $string2 =~ y/a-z/A-Z/; # Getting translated strings print "$string1\n"; print "$string2\n"; Output: GFG IS A COMPUTER SCIENCE PORTAL GEEKSFORGEEKS Example 2: This example uses y operator for translating from upper case to lower case. Perl #!/usr/bin/perl # Initialising some strings $string1 = 'GFG IS A COMPUTER SCIENCE PORTAL'; $string2 = 'GEEKSFORGEEKS'; # Calling to y function $string1 =~ y/A-Z/a-z/; $string2 =~ y/A-Z/a-z/; # Getting translated strings print "$string1\n"; print "$string2\n"; Output : gfg is a computer science portal geeksforgeeks Note: This y operator does the task of lc() function and uc() function as well as it translates the input characters into numeric form etc. Example 3: This example uses y operator for translating from upper case to numeric form. Perl #!/usr/bin/perl # Initialising some strings $string1 = 'GFG IS A COMPUTER SCIENCE PORTAL'; $string2 = 'GEEKSFORGEEKS'; # Calling to y function $string1 =~ y/A-Z/0-9/; $string2 =~ y/A-Z/0-9/; # Getting translated strings print "$string1\n"; print "$string2\n"; Output : 656 89 0 29999949 9284924 999909 6449959964499 Create Quiz Comment K Kanchan_Ray Follow 3 Improve K Kanchan_Ray Follow 3 Improve Article Tags : Perl perl-operators Perl-String-Operators Explore BasicsPerl Programming Language2 min readIntroduction to Perl7 min readPerl Installation and Environment Setup in Windows, Linux, and MacOS3 min readPerl | Basic Syntax of a Perl Program10 min readHello World Program in Perl3 min readFundamentalsPerl | Data Types3 min readPerl | Boolean Values3 min readPerl | Operators | Set - 112 min readPerl | Operators | Set - 27 min readPerl | Variables4 min readPerl | Modules3 min readPackages in Perl4 min readControl FlowPerl | Decision Making (if, if-else, Nestedâif, if-elsif ladder, unless, unless-else, unless-elsif)6 min readPerl | Loops (for, foreach, while, do...while, until, Nested loops)7 min readPerl | given-when Statement4 min readPerl | goto statement3 min readArrays & ListsPerl | Arrays6 min readPerl | Array Slices3 min readPerl | Arrays (push, pop, shift, unshift)3 min readPerl List and its Types4 min readHashPerl Hash4 min readPerl | Hash Operations8 min readPerl | Multidimensional Hashes6 min readScalarsPerl | Scalars2 min readPerl | Comparing Scalars6 min readPerl | scalar keyword2 min readStringsPerl | Quoted, Interpolated and Escaped Strings4 min readPerl | String Operators4 min readPerl | String functions (length, lc, uc, index, rindex)4 min readOOP ConceptsObject Oriented Programming (OOPs) in Perl7 min readPerl | Classes in OOP6 min readPerl | Objects in OOPs6 min readPerl | Methods in OOPs5 min readPerl | Constructors and Destructors4 min readPerl | Method Overriding in OOPs6 min readPerl | Inheritance in OOPs7 min readPerl | Polymorphism in OOPs4 min readPerl | Encapsulation in OOPs6 min readRegular ExpressionsPerl | Regular Expressions2 min readPerl | Operators in Regular Expression4 min readPerl | Regex Character Classes3 min readPerl | Quantifiers in Regular Expression4 min readFile HandlingPerl | File Handling Introduction7 min readPerl | Opening and Reading a File4 min readPerl | Writing to a File3 min readPerl | Useful File-handling functions2 min read Like