#!/usr/bin/perl

use strict;

my $pont = qr{[.!?]+};                            ## punctuation
my $abrev = qr{\b(?:Pr|Dr|Mr|[A-Z]|i\.e|e\.g)\.}; ## abbreviations
my $header = qr{(=+ .*? =+)};

$/ = "";

while(<>) {
    chomp;                     ## for each paragraph,

    s/\h*\n\h*/ /g;            ## remove \n
    s/($pont)\h+(\S)/$1\n$2/g; ## punctuation+space
    s/($abrev)\n/$1 /g;        ## undo \n after abbreviations
    s/$header\h+(\S)/$1\n$2/g; ## vimwiki headers

    print "$_\n";
}