local $_; # Read entire file into $_. { local $/; $_ = ; } # Execute substitutions once each. s/^[ ]+//mg; s/[ ]+$//mg; s/ :000[AP]M | 99991231 | Jan\ 1\ 1900\ 12:00:00 //xg; s/[ ]*~\t~[ ]*/~/g; # Output entire file. print;