my $data = '[-3|1|29x250+46+26|200+300+444|Get][-3|1|29x250+46+26|200+300+444|Get][-3|1|29x250+46+26|200+300+444|Get]'; my $REGEX_COLLECTION = '(\[.*?\])'; my $REGEX_TEXT_RESPONSE = '\[(.*?)\|(.*?)\|(\d+)x(\d+)\+(\d+)\+(\d+)\|(\d+)\+(\d+)\+(\d+)|(.*?)\]'; my @splits = split( $REGEX_COLLECTION, $data ); foreach (@splits) { print "The split value is $_ \n"; if ( $_ =~ m/$REGEX_TEXT_RESPONSE/g ) { print "The first split is $1 \n"; print "The second split is $2 \n"; print "The tird split is $3 \n"; print "The fourth split is $4 \n"; print "The fifth split is $5 \n"; print "The sixth split is $6 \n"; print "The seven split is $7 \n"; print "The eight split is $8 \n"; print "The nine split is $9 \n"; print "The tenth split is $10 \n" } }