use strict; my $lineshapesline1 = 'SHAPES GREEN1;SIZE 240 500 340 930;SIZE 350 500 240 590;SIZE 295 390 015 490;SIZE 350 210 760 300;SHAPES GREEN2;SIZE 450 310 680 690;SIZE 450 110 680 490;SIZE 215 800 560 900;'; my @array; while ( $lineshapesline1 =~ /(SHAPES.*?)(?=SHAPES|$)/g ) { push @array, $1; } print "$_\n" for @array; __END__ SHAPES GREEN1;SIZE 240 500 340 930;SIZE 350 500 240 590;SIZE 295 390 015 490;SIZE 350 210 760 300; SHAPES GREEN2;SIZE 450 310 680 690;SIZE 450 110 680 490;SIZE 215 800 560 900;