What the hell does this line
$cwd =~ qw "(/.*)/" ; do and what do you expect it to do?
The
=~ operator is for binding Regular Expressions to a variable, ex:
$foo=~m/stuff/;
qw Is an operator that splits a group of words on whitespace. It returns a list. Feeding it's output to the =~ operator probably doesn't do what you want (I'm not really sure what it does do for that matter).