in reply to How to substitute something from only between two specified charecters

With just one problematic field that contains spaces you can still split the whole line on spaces without first modifying it by using the third argument to limit the number of fields. Work first from the left leaving the field with spaces along with the rest of the line in the "remainder" part of the string. Then, by using reverse, work in from the right, again with a limit, on the reversed "remainder" to get the rest of the fields; the field with the spaces is the last field and is not disturbed because of the limit to the split.

use strict; use warnings; use 5.010; my @dataLines = ( q{>cds:AEA30293 A/Netherlands/2223b/2009 2009/11/18 HA}, q{>cds:ADD23250 A/District of Columbia/INS17/2009 2009/10/26 HA}, q{>cds:ADX98640 A/San Diego/INS13/2009 2009/10/19 HA}, q{>cds:ADD97035 A/Wisconsin/629-D00036/2009 2009/09/15 HA}, ); say q{=} x 60; foreach my $dataLine ( @dataLines ) { say $dataLine; my @elems; ( $elems[ 0 ], my $remainder ) = split m{\s+}, $dataLine, 2; @elems[ 3, 2, 1 ] = map { scalar reverse } split m{\s+}, reverse( $remainder ), 3; say for @elems; say q{=} x 60; }

The output.

============================================================ >cds:AEA30293 A/Netherlands/2223b/2009 2009/11/18 HA >cds:AEA30293 A/Netherlands/2223b/2009 2009/11/18 HA ============================================================ >cds:ADD23250 A/District of Columbia/INS17/2009 2009/10/26 HA >cds:ADD23250 A/District of Columbia/INS17/2009 2009/10/26 HA ============================================================ >cds:ADX98640 A/San Diego/INS13/2009 2009/10/19 HA >cds:ADX98640 A/San Diego/INS13/2009 2009/10/19 HA ============================================================ >cds:ADD97035 A/Wisconsin/629-D00036/2009 2009/09/15 HA >cds:ADD97035 A/Wisconsin/629-D00036/2009 2009/09/15 HA ============================================================

I hope this is of interest.

Update: Modified code to change order of array slice and thereby eliminated the final reverse

Cheers,

JohnGG