Things you are doing wrong:
- Not indenting your code
- Not providing a working sample
- Not providing sample data
- Not providing sample output
- Not providing expected output
- Using a while loop where most likely you should use a for loop
- Apparently using 1 based indexing for arrays (Perl uses 0 normally)
- Using an empty else
- Explicitly listing all the elements in an array rather than using a slice
- (probably wrong) omitting a space in the string for join
- (possibly wrong) using a variable ($subcounter) without apparent initialisation
- Describing a problem you haven't provided code for
The last one is the kicker!
DWIM is Perl's answer to Gödel