The //x option is designed to make the actual regexp easier to read, so literal spaces are ignored; in this case, though, you're not using literal spaces but instead interpolating a variable as the pattern; moreover you don't want the spaces ignored but rather mapped to an arbitrary sequence of white space.
You can't do that without providing the pattern to do it. It isn't entirely clear from your description what that pattern should be, but one possibility would be:
$words_to_match =~ s/^\s*|\s+|\s*$/\\s*/g; $output_line =~ /$words_to_match/i; ...
Note that this replaces the beginning, the end, and any sequence of whitespace within the variable with 'match zero or more whitespace characters', so it would also match "helloworld"; if you want interior breaks to require at least one space in a matching string, you need to handle the endpoints separately from the interior breaks:
$words_to_match =~ s/^\s*|\s*$/\\s*/g; $words_to_match =~ s/\s+/\\s+/g; $output_line =~ /$words_to_match/i; ...
Hugo
In reply to Re: disregard spaces while matching ?
by hv
in thread disregard spaces while matching ?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |