in reply to strange regexp problem
1. never use $1 without checking if a regex succeeded. you have
to provide a default value for this case or do something else.
2. you're printing $cwd after the regex and assigning. use print-debugging by just printing $cwd before the regex.
3. using qw() as a regex is confusing IMHO. you could use qr() or just m//
4. what are you trying to accomplish with that snippet?