Для замены _[0-9]
на ,
вы можете сделать this :
$s =~ s/_([0-9])/,$1/g
#the same without capturing groups
$s =~ s/_(?=[0-9])/,/g;
Edit:
Чтобы получить дополнительную запятую после 2
, вы можете сделать это:
#This puts a , before all whitespace.
$s =~ s/_(?=[0-9])|(?=\s)/,/g;
#This one puts a , between [0-9] and any whitespace
$s =~ s/_(?=[0-9])|(?<=[0-9])(?=\s)/,/g;