Regular expression equivalent to chomp

perl, regex

Solution

What `chomp` does is remove the value of `$/` from the end of its argument string (or `$_` if no argument). So the equivalent regex would be:

s#\Q$/\E\z##;

Note the use of other delimiter for `s///` to avoid problems with the `$/` variable.

However, there is no benefit to using such a regex, rather the opposite. This is a purely academic question, in my opinion.

Problem

i have seen somewhere instead of using chomp in perl we can use some regular expression to achieve the same task. Can anyone tell what is the regular expression will meet chomp in perl Thanks in advance

Original source