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


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

I guess that you are trying this with a file that has been generated on Windows and then transferred to a UNIX box. You end up with extra ^M chars when you look at the file using vi. Try trimming the surplus whitespace using a regex
#!/usr/bin/perl -w use strict; while (<MYFILE>){ s/\s+$//; if (/NEXT LINE MARKER/) { my $nextLine = <MYFILE>; $nextLine =~ s/\s+$//; print "$nextLine\n"; # do stuff with the next line here. } }