in reply to Is it possible to use repetition within a Regular Expression Substitution?

I would write that as:
my $stars = "*" x 80; s/^-{40}\cM*$/$stars/;
Or even
my $stars = "*" x 80; my $dashes = "-" x 40; s/^$dashes\cM*$/$stars/;