in reply to nested replace

Another alternative:

use Regexp::Common 'comment'; $str=~s/($RE{comment}{C})/($a=$1)=~s#[^\n]##g;$a/ge;