# untested... I'm sure this doesn't really work... while( $line =~ m{\G\s*(\[\w0-9]+|"(?:[\w0-9]|"")+")}g ) { do_something_with_match($1); }