in reply to Replace a word in a line except for the last char of the word?
Hi, just try the below code (is this meet your requirement?)
my $line = '<br> 2<br> 3<br> 4'; my $temp = $line; while ($temp =~m#(<br>)(.+?)( \d+)#gsi) { my $full= $&; my $text=$1; my $space = "$2"; my $digit = "$3"; my @arr=(); (@arr) = $space =~s#( )# #gsi; my $nbsptext = " " x "@arr"; $line =~s#$full#${text}${nbsptext}${digit}#gsi; $full=""; } print $line; output: <br> 2<br> 3<br> 4
|
|---|