in reply to while(eval $c){} with self-modifying $c.

I have to agree with Dominus here. It's non-trivial to write a program that writes valid Perl. Save it for when you really need it.

I'll go further, and guess that you'll be switching back and forth between n possible code snippets, where n is less than 100. In that case, use coderefs and an array or hash:

my @code = ( sub { print "This does something!\n" }, sub { print "This also does something!\n" }, ); for (@code) { $_->(); }