my @matches; for ( @inp_lines ) { push @matches, ( /(SHAPES \w+;(?:SIZE[ \d+])+;)/g ); }