I think split is exactly what you want to use. Regexes are inefficient way to do what split does.
To my mind, the better cleanup would be to get rid of the named variables and use array manipulation. Since you say in a followup that you want to read colon-delimited pairs from STDIN and keep the results, you probably want to make a whole array of them. This little slug places the pairs in an array with the first of each in even-numbered position:
my @pairs = map {chomp; split ':', $_, 2} <STDIN>;
If one element of the pairs is suitable (no repetition), you can also make a hash, my %pairs from the map output.
After Compline, Zaxo
Update: Added a chomp, assuming that's desirable. |