I would like remove only spaces and ignore tabs in a string

Tabs are ascii character 0x09; spaces are 0x20. Replacing spaces will not affect tabs…

$str = "1 2 3\t4 5 6\t7 8 9\n";
$str =~ s/ //g;
# $str is now "123\t456\t789\n"

Take a look at perlrequick for an introduction to regular expressions.

Browse More Popular Posts

Leave a Comment