my $s = "a1: a,b,c"; # instead of just a colon, first split on colon preceded # or followed by optional whitespace my ($prefix, $rest) = split /\s*:\s*/, $s; # now, $prefix = "a1" and $rest = "a,b,c" # now do the same for commas my @rest = split /\s*,\s*/, $rest; # now, @rest = ( 'a', 'b', 'c' )