in reply to problem in printing the result in the out put file

I use a similar approach to toolic's suggestion, except I specifically target line endings and anchor the pattern:

s/[\n\r]+$// for (@ip);

Most of the time, this is enough, because when I "export" text files to Ms Windows users, I use unix2dos to convert the line endings to MS Windows convention.

When I want or need a tool that robustly works under both MS Windows and Linux/Unix/POSIX, I would combine that with Eily's suggestion and add in ':raw' mode, like:

my @ip; { local $/ = "\n"; open my $dat, "<:raw", $in_file or die "Can't open file $in_file: $! +"; @ip = <$dat>; s/[\n\r]+$// for (@ip); close $dat; }

(There's probably a module on CPAN that does this, and maybe even add support for legacy MacOS line endings.)