use strict; use warnings; use feature qw{ say }; my $winLineTerm = qq{\x0d\x0a}; my( $file, $writeFH, $readFH ); say q{-} x 20; open $writeFH, q{>}, \ $file or die $!; print $writeFH qq{ABC${winLineTerm}DEF$winLineTerm}; close $writeFH or die $!; say q{No measures}; open $readFH, q{<}, \ $file or die $!; while ( <$readFH> ) { say q{Before chomp()}; say for map { sprintf q{ %#02x}, ord } split m{}; say q{After chomp()}; chomp; say for map { sprintf q{ %#02x}, ord } split m{}; } close $readFH or die $!; say q{-} x 20; say q{Change default line terminator}; { local $/ = $winLineTerm; open $readFH, q{<}, \ $file or die $!; while ( <$readFH> ) { say q{Before chomp()}; say for map { sprintf q{ %#02x}, ord } split m{}; say q{After chomp()}; chomp; say for map { sprintf q{ %#02x}, ord } split m{}; } close $readFH or die $!; } say q{-} x 20; say q{open() with :crlf I/O layer}; open $readFH, q{<:crlf}, \ $file or die $!; while ( <$readFH> ) { say q{Before chomp()}; say for map { sprintf q{ %#02x}, ord } split m{}; say q{After chomp()}; chomp; say for map { sprintf q{ %#02x}, ord } split m{}; } close $readFH or die $!; say q{-} x 20; #### -------------------- No measures Before chomp() 0x41 0x42 0x43 0xd 0xa After chomp() 0x41 0x42 0x43 0xd Before chomp() 0x44 0x45 0x46 0xd 0xa After chomp() 0x44 0x45 0x46 0xd -------------------- Change default line terminator Before chomp() 0x41 0x42 0x43 0xd 0xa After chomp() 0x41 0x42 0x43 Before chomp() 0x44 0x45 0x46 0xd 0xa After chomp() 0x44 0x45 0x46 -------------------- open() with :crlf I/O layer Before chomp() 0x41 0x42 0x43 0xa After chomp() 0x41 0x42 0x43 Before chomp() 0x44 0x45 0x46 0xa After chomp() 0x44 0x45 0x46 --------------------