Just one slight problem... $$ is the current program pid, since $1 is not a scalar ref to dereference. It might be better to quote the first $ sign if this behaviour is not desireable (which would have been the cause for half of the original problem as well).