in reply to Trim blanks from the beginning and end of a multi-line string

Are you sure that there are no other invisible characters at the end of the file (such as carrige return "\r")? If there are you should include them in the regexp:
$body=~s/[\n\r]+$//;

Replies are listed 'Best First'.
Re^2: Trim blanks from the beginning and end of a multi-line string
by Marshall (Canon) on Jan 29, 2012 at 16:28 UTC
    Normally that is not needed because this \n is "magical" - it handles <LF> Unix style "new line" and Windows style <CR><LF> "new line". If you write a "\n", it will write that platform specific type of "new line". When you read that file on the other platform, the other platform's "newline" is ok.

    Update: For the folks who may not be up on the terminology... CR, Carriage Return is what \r is. LF, Line Feed is the character that Unix will write for "\n". Windows will write both for a "new line". As trivia, the convention for network transmission of lines of text (like over a socket) is the same as Windows, <CR><LF> that's true even on Unix system. Perl handles all this oddness in a very nice and magical way - basically the "right thing" happens (Do What I Meant).