If the regular expression doesn't match you don't have `$1` defined. I guess you mean `$path`.

Also, the regexp only matches individual components of a path. You miss / in your class `/etc/passwd` doesn't match. Maybe

```perl
$path =~ m{^([/-. &#\@\w])+$}
```
?