Lines are broken to fit 70 columns (you can easily change it to any other value). Lines starting with >, |, or : are not touched (you can easily change this set of quoting symbols). Breaks are inserted only at space characters, so long words (such as URLs) are not destroyed.
1 | #!/usr/bin/perl
2 | undef($/);
3 | $_=<STDIN>;
4 | 1 while s/^(?=[^>|:].{70,})(.{0,69}[^ ]|[^ \n]+?) +(?=[^ \n])/$1\n/m;
5 | print;