sub remove_trailing_newline { $_[0] =~ s/[\r\n]+\Z//; } #### if ( m/(\r\n|\n\r|\r|\n)$1/ ) { # two newlines in a row! }