Perl search and replace in range using variable

Hi. I have a file with asterisk field separators and backslash line terminators. The first field in each line names the line type. I am trying to process each range separately. Here's what the data looks like:

BADATA\
LS*DATA1*DATA2*00020
\
TA*DATA1*DATA2*DATA3*\
TA*DATA1*DATA2*DATA3*\
LE*DATA1*DATA2*00020*\
LS*DATA1*DATA2*00020*\
TA*DATA1*DATA2*DATA3*\
TA*DATA1*DATA2*DATA3*\
LE*DATA1*DATA2*00020*\
BA*DATA\

So what I want do is get the ranges of text between LS and LE. Then with each range I want replace the '00020' occurrences with a number that is increased each iteration. So on the first pass '00020' is changed to '1' then on the next range 00020 is changed to '2'. Here's how the data should look after processing:

BADATA\
LS*DATA1*DATA2*1
\
TA*DATA1*DATA2*DATA3*\
TA*DATA1*DATA2*DATA3*\
LE*DATA1*DATA2*1*\
LS*DATA1*DATA2*2*\
TA*DATA1*DATA2*DATA3*\
TA*DATA1*DATA2*DATA3*\
LE*DATA1*DATA2*2*\
BA*DATA\

I can get the ranges with this using sed and awk:

/^LS\*/,/^LE\*/

Since I want to work with the range of data I can't just process it line by line because I need to update the range of data. Everything seems to treat the ranges as one big range. I am trying to learn perl too so I thought maybe I could use perl but I don't know how to put a multi-lined string into a perl array. If anyone has any suggestions as to what would be the best approach I would be very grateful.

Thank you.

Look at the /m and /s modifier of m// for regular expression (same for s///). They should work for you.

perlre - perldoc.perl.org