in reply to Split a string into individual words

Basically, qw() is the wrong construct in your second bit of code. qw() assumes that whatever is in the delimiters is text, not a variable. What you want is split.

#replace qw($a); #with my @words=split(/\s+/,$a);

Later