in reply to Chomp not working

If you want to remove leading and trailing white space, that is trim. https://metacpan.org/pod/String::Util#trim-string

If you want to trim and flatten internal white space, that is crunch. https://metacpan.org/pod/String::Util#crunch-string