in reply to use of string terminator within a subroutine

From perldoc perldata: "The terminating string must appear by itself (unquoted and with no surrounding whitespace) on the terminating line." It should work fine if you just remove the leading space from the GOOFY line. Your first example also does not work for the same reason. Note that there is no difference in the usage of here-documents being in sub's or in main.