use v5.12; use warnings; while ( ) { chomp; say "'$_'"; say $3 while # print 3rd capture $_ =~ /(^|\s) # starts with line's start or whitespace ("?) # capture optional double-quote inside (otherwise empty string) ([^\2]*?) # capture anything non-quote \2 # end with same quote (?=(\s|$)) # look-ahead at following whitespace or line's end /xg # g= loop _globally_ over all matches x=allow multiline extended regex } __DATA__ 50 0 "R0 G255 B0 A255" "Solid" 118 1 "R0 G0 B0 A255" "R0 G0 B0 A255" 0 70 0 "R0 G255 B255 A255" "Solid" 118 1 "R12 G12 B12 A255" "R12 G12 B12 A255" 0