in reply to Problem with function

The scope of the lexical variable $type is from its declaration to the end of the file, not including the body of the function where you're trying to access it.
Bill H
perl -e 'print sub { "Hello @{[shift]}!\n" }->("World")'