Remove newlines from string

Posted on 1998-11-19
Last Modified: 2008-03-03
How can I remove all newlines from a string?
$a = "whatever including newlines";
$a =~ /whatever without newlines/;
Question by:Lee5
  • 2
LVL 51

Accepted Solution

ahoffmann earned 50 total points
ID: 1206368
  chop $a;
   chomp $a;
LVL 51

Expert Comment

ID: 1206369
oops, if they are not at end of string:

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


Author Comment

ID: 1206370
The oops did the trick

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl script to parse xml file 2 96
How to strip .csv from file name 9 75
iSeries PERL Scripts 7 128
File Find regex problem 4 57
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now