Source Code Metamorphosis mbomb007 asked us to make a self mutilating program.  Its an interesting challenge, but I personally don't like to encourage my programs to be self-mutilating.  I like to think that, at the heart of every program is a beautiful butterfly waiting to break out.

As such, for my first ever Code Golf challenge, I challenge Stack Exchange to metamorph a butterfly.  Your program should accept its own code as input and output I am a caterpillar! followed by the code for another program in the same language (you may put a divider between the outputs or not... but we're talking butterflies, so prettiness counts!). This second program should output I am a beautiful butterfly!

Metamorphosis: This program should modify itself, which is why it is being passed itself as input.  I don't want a boring nested program that is nothing but a print statement I am a caterpillar! followed by printing source code.  You have to metamorph the code itself, so the most boring acceptable answer is one which prints I am a caterpillar, then rips a string out of the input (which happens to be code) and prints that.  Of course, this is a very tricky little requirement to write, so it should be thought of as a "spirit of the challenge."  The formal requirement is going to be set at "If your program is given a random string of the same length as your program, there should be less than a 5% chance of printing I am a butterfly when the second program is run."

Summary:


Write a program which, when provided its own code as input, prints I am a caterpillar! followed by a block of source code (with a delimiter between them or not).
This second block of source code, when compiled/interpreted as the same language, prints I am a beautiful butterfly!
If your program is not fed its own source code as input, and is instead given a random string of characters that does not match its own code, the result must either fail to compile/interpret, or not print I am a butterfly! for at least 95% of random strings (spirit: you are expected to read your own source code from the input, and stitch it together into a butterfly).


I'm comfortable with you not proving this, so long as you're holding to the spirit of the metamorphosis idea, modifying your own code, but if you're trying to play loophole games to work around using your inputs, expect to have to prove it.

Standard loopholes apply


I'd like these to be judged by their beauty, but that's a decidedly non-quantitative approach, so the usual "number of bytes" route can be used to judge

Bonus: -20% - pick any 3 letter string that doesn't match the first 3 letters of your program.  If I run the caterpillar program, but modify the input so that the first 3 character are changed to the specified ones, print I am Batman! instead.   Always be Batman.  (Same random string rules apply for this... metamorphosis!)

Trivial example (python):

"""
    print "I am a beautiful butterfly!"
    #print "I am Batman!"
"""
import sys
code = sys.stdin.read()
if code.startswith("YYZ"):
   # swap the comments between the print statements
   code = code.replace("#print", "_a").replace("print", "#print").replace("_a", "print")
code = [3:] # remove """ or XYZ
code = code.split('"""')[0]
print "I am a caterpillar!"
print code
Befunge-98, 602 bytes
                                        &quot;^@&lt;&quot;v@@
                                     &quot;'I'&quot;00v&gt;00g::
                                   &quot;@v&quot;0v@@@&gt;g::a&quot;&gt;#&quot;
                                 &quot;a&quot;&gt;v@@&gt;      0g::'&quot;1&gt;                                 /
                             &quot;:\&quot;'&quot;v@&gt;            'm'&quot;00g:a                       &gt;&quot;@v$&quot;
 &quot;lufituaeb&quot;'&quot;'v00ga&quot;@v\&quot;'&quot;:'b\00v@&gt;                :'a\&quot;:*84&gt;&quot;00ga&quot;\&gt;@@@@_,#:&gt;&quot;00g:a'&lt;'&quot;
&quot;et&quot;'&quot;'va'v'&quot;:'l\00g5k:'&quot;&quot;y!&quot;&gt;&gt;v@&gt;                    g::'''&quot;&quot;ut&quot;'&quot;'&gt;a'&lt;'&quot;&quot;fr&quot;'&quot;00g3k:'&quot;&gt;
 &quot;ma&quot;00g&gt;'I~48*-~48*-+#@_&gt;:#,_@&gt;                        '&quot;aa&quot;---&quot;aa&quot;!rallipretac&quot;00g:'a\

Tested in PyFunge.
When run with a string not starting with 2 spaces (probability well over 95% when random) outputs nothing. This isn't exactly what the OP is looking for, but fits the specification.
When passed a string starting with 2 spaces (like itself) outputs this:
I am a caterpillar!

---

&quot;!y&quot;       &quot;l&quot;v
v&quot;te&quot;     &quot;rf&quot;&lt;
&gt;&quot;tu&quot;'   &quot;b&quot;\v@
 v&quot;beautiful&quot;&lt;
  &gt;:#,_@@@@&gt;\
 &gt;48*:&quot;a&quot;\:$v@
  &quot;ma&quot;   v@#&gt;
   'I'   &lt;@^

The lower part of that, in turn, outputs:
I am a beautiful butterfly!