A polymorphic quine

I thought it might be fun to write a "polymorphic virus", but that would involve learning executable file formats and machine code, which sounds like a lot of effort. So instead I went for the next best thing: Perl instead of machine code, and self-replicating code in the form of a quine rather than "infecting" other executables.

When you run this code, it will output a new version of itself, which you can run again to get another version, etc. Unlike a regular quine, which will produce an exact copy of its source code, this program is polymorphic: Its output is functionally identical to the original, but the code might look completely different. This is just a proof-of-concept, but it does try to introduce variations in all parts that a simple static scanner might use for detection (such as signatures in an antivirus). There are still fixed parts, but they're small and generic (such as ; or =) and can be found in most any perl script.

(my $Edw70Kp = "|ygn`hjs\nmo\\yjc]eyuy}YUl[h^y:YWyw\nmo\\ym`gnyu\nyyyygsy\"}mnl#y7y:Y5\nyyyyl_nolhymjlchn`\"{p~p^{&y}mnl#\nyyyyyyyyc`yl[h^\"#y6y*(,5\nyyyy}mnly7xymu\"UXy'xW#v\"U{V}V:VVW#wu\nyyyyyyyy^_`ch_^y},y9y{VV},{y4\nyyyyyyyy}+y_ky{Vh{y9y{VVh{y4\nyyyyyyyymjlchn`\"{VVr~*,r{&yil^y}+#\nyyyyw_a5\nyyyy!{!y(y}mnly(y!{!\nw\n\ngsy}p[ly7y!}!y(ydichy!!&yjc]e\"![!y((y!t!&y!;!y((y!T!&y!Y!#&yg[jyjc]e\"![!y((y!t!&y!;!y((y!T!&y!Y!&y!*!y((y!3!#&y'-y((yl[h^y++5\ngsy\"}ip[l#y7y}?^q1*Ejy7xy)7yV}\"Vq%#y7)5\n}?^q1*Ejy7xym)V}}ip[lV\\)}p[l)a5\n\ngsy}h_rny7yjc]e\"!!&y!gsy!&y!ioly!#y(y}p[ly(y!y!y(yjc]e\"!7!&y!(7!&y!vv7!#y(y!y!5\n\nc`y\"l[h^\"#y6y*(/#yu\nyyyygsy}ey7ydichy!!&yg[jyuy]blyl[h^y,/0ywy+y((yf_hanb\"}?^q1*Ej#5\nyyyy}h_rny(7ym`gn\"}e#y(y!yXy!y(ym`gn\"}eyXy}?^q1*Ej#5\nwy_fm_yu\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