my @AUBBC_TAGS = ('b','i','sub','sup','pre','ul','ol','small','big','li','p','h1','h2','h3','h4','h5','h6','div','strong'); my $message = '[b] stuff [i] stuff [/i] [/b]'; foreach (@AUBBC_TAGS) { $message =~ s{\[(.?)?$_\]}{<$1$_>}xg; } print $message;