my %escapes = qw( & & < &LAB; > &RAB; ( &LCB; ) &RCB; [ &LSB; ] &RSB; ); sub escape(_) { $_[0] =~ s(/[&<>()\[\]])/$escapes{$1}/gr }