foreach (@array){ # iterate the array while(m#/MSS#g){ # find a /MSS substr($_,pos,do { m#/#g; pos }) =~ s/ (?!\*)//g; # find a closing / # substring the range currently in effect /MSS to / # replace all ' ' (replace with \s if applicable) # not followed by a * with nothing } }