05 0 1–2 2 UN Transaction Code #### $string = "05 0 1–2 2 UN Transaction Code"; $found = 0; # Make a fist with left hand (no fingers) $position = 0; # We're at the start of the string; # put your right index finger there. while( $found != 5 && $position != length $string ) { # Set up a loop that stops once # we've extended all five fingers. # Check if the character at the current position is a space. if( substr( $string,$position,1) eq q{ } ) { # If it is, replace it with a comma. substr( $string, $position, 1, q{,} ); ++$found; # And extend one finger to count that we # found a space. } ++$position; # Each time through the loop, advance our # position marker to the next character. } # Repeat unless we're done.