in reply to help! reading in special characters from file

If you just want to remove the extra spaces then use the \s+ construct:

$lines[0] =~ s/\s+/ /g;
The regex says substitute 1 or more spaces with a single space. (Note: you have $line[0] which I assume is a typo). Check out perlre for more info.

-derby

Replies are listed 'Best First'.
Re^2: help! reading in special characters from file
by graff (Chancellor) on Jun 02, 2007 at 16:35 UTC
    That will turn tabs into spaces (maybe not a bad thing, depending on the situation), and will turn the newline at the end into a space (usually a bad thing, depending on the situation).

    So one should decide exactly what is needed, depending on the situation:

    # pick one of: s/ +/ /g; # just reduce strings of consecutive spaces s/[ \xA0]+/ /g; # reduce and normalize space/nbsp strings s/[ \xA0\t]+/ /g; # include tabs as well s/\s+/ /g; # all kinds of whitespace, including newlines