Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi how do I remove new lines between two separate STRINGS on two different lines ?

Replies are listed 'Best First'.
Re: Remove newline between strings
by choroba (Cardinal) on Jun 25, 2014 at 16:12 UTC
    Your question doesn't give many details, but maybe you need something like the following?
    #!/usr/bin/perl use warnings; use strict; while (<DATA>) { my $remove_new_line = /string1/ .. /string2/; chomp if $remove_new_line and 0 > index $remove_new_line, 'E'; # not the last line print; } __DATA__ x y z string1 a b c string2 1 2 3

    Output:

    x y z string1abcstring2 1 2 3
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Than you this helped a lot.
Re: Remove newline between strings
by RonW (Parson) on Jun 25, 2014 at 16:09 UTC

    A better description and sample code would help us better understand your question.

    However, maybe this:

    chomp $string1; chomp $string2;

    If you are looking to remove embedded newlines:

    $string1 =~ s/[\r\n]+//g;

    will remove any of the most common line terminators found in text files.