http://www.perlmonks.org?node_id=535160


in reply to Re^4: Matching string, then getting next line
in thread Matching string, then getting next line

Actually you'd better remove only the ending "CR" characters, not spaces :
while (<MYFILE>) { s/\r\n$/\n/g; ... }
This simply replace "<CR><LF>" (DOS end of lines) with "<LF>" (Unix end of line)