in reply to pearl script working but is changing to attachment
In addition to subroutines, take a look at here documents (third day of programming). See also Quote and Quote-like Operators.
Give a man a fish: <%-{-{-{-<