Question: I am using qx in Perl to execute commands in a Linux machine.

I'm trying to parse some output in Perl but don't know how to replace the new-line character in multi-line output.

I have been trying something like this:

```
$result =~ s/\\n/||/g;

```

I seem to recall a '\r' with some OSs and I have been trying different combinations with '\n'.

Also, I am starting to have a bunch of lines that look like this, and would like to combime them:

```
$result =~ s/ bytes from /|/g;
$result =~ s/ \(/|/g;

```

Answer: 
If `\` is either the start of special sequence (if it's followed by a letter), or it causes the next character to be matched literally (if it's followed by a non-letter). Therefore,

```
s/\\n/

```

matches `\` followed by `n`. `\n` is a special sequence that matches a newline, so you want

```
/\n/

```

So you could use

```
my $result = qx{ ... };
$result =~ s/\n/||/g;

```

[perlre](http://perldoc.perl.org/perlre.html)

---

Regarding the rest,

```
$result =~ s/ bytes from /|/g;
$result =~ s/ \(/|/g;

```

is simply

```
$result =~ s/ bytes from | \(/|/g;

```
You shouldn't be using double backslashes, for one thing.

Here is how you can do it:

```
$text = <<EOS;
div class equals main
span id equals marquee
blog! slash span slah div
EOS

print "Before: $text \n\n\n\n";

$text =~ s/\n/\|\|/g;

print "After: $text \n\n\n\n";

```

Here is a codepad for it: <http://codepad.org/k0oA2YX4>