字符串中的perl空格替换

Ker*_*y82 0 perl

我有这两种字符串:

EVASA           2144
IN ELABORAZIONE         16278
Run Code Online (Sandbox Code Playgroud)

我需要一些perl脚本来替换所有空格只有一个.

我需要的输出是:

EVASA 2144
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

Dav*_*ogt 7

你可以使用一个非常简单的正则表达式:

#!/usr/bin/perl
use strict;

my $line = 'EVASA           2144';

# This is the line that actually does the work
$line =~ s/\s+/ /g;

print $line, "\n";
Run Code Online (Sandbox Code Playgroud)