Perl chop() and chomp()
Both the functions are quite similar. Both of them remove one character from the end of the given string.
The Perl chop() function removes last character from a string regardless of what that character is. It returns the chopped character from the string.
Perl chop() example
Look at the output, at first, variable $a is printed after chopping. Then variable $b is printed which returns the chopped character from the string.
The chomp() function removes any new line character from the end of the string. It returns number of characters removed from the string.
Perl chomp() example
AEIOU 0 AEIOU 1
Look at the output, at first, variable $a does not contain any new lone character. Then it is passed in variable $b and printed. It returns 0 as no character is removed.
Now, variable $a contains a new line character. When it is passed in $b, it returns 1 as it removes one new line character.