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
In reply to Re: Replace a word in a line except for the last char of the word?
by perlsen
in thread Replace a word in a line except for the last char of the word?
by Ronnie Doorzon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |