in reply to simple regex problem

All I want to do is swap any number of spaces (the first 2) with ":"

you want to replace the first two ocurrences of one or more spaces with ":"? and then replace any other more-than-one spaces (damn, my english sucks today!) with one space?

$line =~ s/\s+/ /g; # replace more than one space with one space $line =~ s/ /:/ for (1, 2); # replace the first two spcs with a colon #- does not work if there's only one space - $line =~ s/ (\S+) /:$1:/;
couldn't think of a way to do it with a single substitution...

update. fixed bug when there is only one space. thanks blakem!

hope it helps,