use strict; use warnings; $| = 0; my $str="A: Gold, Black, Purple, Blue, Red B: Black, Neon Pink, Neon Yellow, Neon Green, Neon Purple, Red, White, Neon Orange, Navy"; my @records; my @strings = $str =~ m/(\w+:(?:(?!\b\w+:).)*)/g; push @records, map {[m/(\w+:)/, m/(?<=:|,)\s([^,]*,?)/g]} @strings; print "@$_\n" for @records;