in reply to clearing spaces from data input

From your example, it looks like spaces are not allowed at all in a1 or s1. If all you really want to do is strip out spaces, this'll do the trick:
$line = "s1:a,first,b, second, c,third"; $line =~ s/ //g; #print $line;
jryan's code is careful to remove only spaces next to commas. But if you want to remove all spaces, s/ //g; is what you want. Well, it's what I would want, anyway...