The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl -p

# Converts a dom to a regular-expression DOM
s/([\(\)\[\]\{\}\.\+\*\?\|\\\^\$])/\\$1/g;
s/id\d+/id\\d+/g;
s/line="\d+"/line="\\d+"/g;
# Remove bogus A-circumflex
s/\xc2//g;
# Deal with unicode characters
s/([\x00-\x09\x0b-\x1f\x7f-\xff\x{0100}-\x{ffff}])/sprintf '\\\\u%04x', ord $1/ge;
# Handle the "Generated on" date
s/(Generated on: *).*/$1.*/;
# Handle the "Generated by" description
s/^( *Generated by *)/$1.*/;
# Accommodate different date formats
BEGIN {
    $time = '(\s+\d+:\d+:\d+(\s+[-+]\d+(\s+\(.+?\))?)?)?';
    ($timere = $time) =~ s/\\([()])/\\\\\\$1/g;
}
s!(\d{4})([-/])(\d{2})\2(\d{2})$timere!\\d{4}[-/\]\\d{2}\[-/\]\\d{2}$time!go;
# Handle uppercase vs lowercase unicode
s/(\\u)([\da-f]{4})/$1(?i)$2/ig;
# Deal with revisions that may change
s/(prest release )\d+(\\\.\d+)+/$1\\d+(\\.\\d+)+/;
if ($AFTER_REVISION) {
    s/\d+(\\\.\d+)+/\\d+(\\.\\d+)+/;
    $AFTER_REVISION = 0;
}
$AFTER_REVISION = /<revision>/;
# Deal with dates that may change
if ($AFTER_DATE) {
    s|\d{4}[/-]\d{2}[/-]\d{2}|\\d{4}[/-]\\d{2}[/-]\\d{2}|;
    $AFTER_DATE = 0;
}
# Deal with perl eval numbers that may change in error messages
s/\\\((eval )(\d+)\\\).*/\\($1\\d+\\).*/;
$AFTER_DATE = /<date>/;
# Perl trapped error message changed between 5.8.0 and 5.8.6.
s/(: )(.*)( trapped by operation mask)/$1($2|.*)$3/;
# System messages may differ in different locales
s/(\\\[Errno \d+\\\])(.*)/$1($2|.*)/;
s/(\bstates: )(.*)/$1($2|.*)/;
# Handle -d output
s!^.*(/Text/Restructured/Writer/dom\\\.wrt, line )\d+!.*$1\\d+!;
# Handle line numbers in error messages
s!\S+(/\S+\\\.(?:pm|wrt),? line )(\d+)(, <\w+> line \d+)?!.*$1($2|\\d+)(, <\\w+> line \\d+)?!g;