Perl | chop() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The chop() function in Perl is used to remove the last character from the input string. Syntax: chop(String) Parameters: String : It is the input string whose last characters are removed. Returns: the last removed character. Example 1: Perl #!/usr/bin/perl # Initialising a string $string = "GfG is a computer science portal"; # Calling the chop() function $A = chop($string); # Printing the chopped string and # removed character print " Chopped String is : $string\n"; print " Removed character is : $A\n"; Output: Chopped String is : GfG is a computer science porta Removed character is : l Example 2: Perl #!/usr/bin/perl # Initialising a string $string = "[1, 2, 3]"; # Calling the chop() function $A = chop($string); # Printing the chopped string and # removed character print " Chopped String is : $string\n"; print " Removed character is : $A\n"; Output : Chopped String is : [1, 2, 3 Removed character is : ] Comment More infoAdvertise with us Next Article Perl | List Functions K Kanchan_Ray Follow Improve Article Tags : Perl Perl-function Perl-String-Functions Similar Reads Perl | chomp() Function The chomp() function in Perl is used to remove the last trailing newline from the input string. Syntax: chomp(String) Parameters: String : Input String whose trailing newline is to be removed Returns: the total number of trailing newlines removed from all its arguments Example 1: Perl #!/usr/bin/per 2 min read Perl | delete() Function Delete() in Perl is used to delete the specified keys and their associated values from a hash, or the specified elements in the case of an array. This operation works only on individual elements or slices. Syntax: delete(LIST) Parameters: LIST which is to be deleted Returns: undef if the key does no 1 min read Perl | ord() Function The ord() function is an inbuilt function in Perl that returns the ASCII value of the first character of a string. This function takes a character string as a parameter and returns the ASCII value of the first character of this string. Syntax: ord string Parameter: This function accepts a single par 1 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 | substr() function substr() in Perl returns a substring out of the string passed to the function starting from a given index up to the length specified. This function by default returns the remaining part of the string starting from the given index if the length is not specified. A replacement string can also be passe 2 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 Like