Remove empty lines and space with Perl

perl

Solution

my $string= "Current configuration : 17448 bytes

                              |  Current configuration : 17331 bytes


 ";

$string =~ s/\s+/ /gs;

print "$string\n"

Prints:

Current configuration : 17448 bytes | Current configuration : 17331 bytes 

Problem

How do I remove empty lines and space from a string? I did a search, but none of the solutions were able to fix my problem. When I print the string, I don't see any special character like \n \t \r. Here is my string: ``` $string= "Current configuration : 17448 bytes | Current configuration : 17331 bytes "; ``` I did the following: ``` $string =~ s/ ++/ /gs; ``` But the output came out like this: ``` Current configuration : 17448 bytes | Current configuration : 17331 bytes ``` And I want it to show like this: ``` Current configuration : 17448 bytes | Current configuration : 17331 bytes ```

Original source