my $content1='' x'; $content1=~s/\&(\#\d*[^;\d]+)/\&$1/gs; print '1:'.$content1."\n"; my $content2='' x'; $content2=~s/\&(\#\d*[^;]+)/\&$1/gs; print '2:'.$content2."\n"; #### 1:'&#22 x 2:'&#22 x #### This is perl 5, version 20, subversion 1 (v5.20.1) built for MSWin32-x86-multi-thread-64int (with 1 registered patch, see perl -V for more detail) Copyright 1987-2014, Larry Wall Binary build 2000 [298557] provided by ActiveState http://www.ActiveState.com Built Oct 15 2014 22:10:49