in reply to foreach problem?

Maybe part of the problem, maybe not, but:
$currentword =~ /^([\w]+)$/;
in your code as you have it does nothing: since you are only looking for a match, the =~ operator doesn't modifiy $currentword, and you don't use the result of the search ($1) in your subsequent calls. In fact, I can't see what the point of this regex is -- Obviously you're looking for the word part of $current word, but you seem to be implying that you only want the word in that regex with nothing else. Maybe you need an if statement on that regex, and then use $1 in the concatenations.