you want to treat $text as a single string use $text =~ s/\n+/\n/sg; # use /mg if you want to treat the string as multiple lines.
-----Original Message----- From: Moore, Larry [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 31, 2002 12:33 PM To: beginners@perl. org (E-mail) Subject: replacing multiple blank lines with a single blank line I want to slurp a file and make multiple blank lines into single blank lines. Here is my code: #! perl -w use strict; my $file = "test.fmt"; open (IN, $file) or die; open (OUT, ">>test.txt"); my $text; { local $/; $text = <IN>; close IN; } # $text =~ s/\0{2,}/\0\0/mg; # this removes all the blank lines # $text =~ s/(^$^$)(^$)+/$1/mg; # also removes all blank lines and complains # $text =~ s/(\n\n)(\n)+/$1/mg; # no improvement here either print OUT "$file\n\n$text\n******************"; close OUT; I have tried a number of substitutions but haven't found the correct formulation. surely I am missing something simple here. Larry ---------------------------------------------------------------------------- -------------------- The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]