sub parse_value { if( peek( qr{['"]} ) ) { parse_string(); ... sub parse_string { my $start = get_pos(); # now a seek position, not a string offset my $str = ''; if( eat("'") ) { # Inside '...', '' is a literal ', all else is just literal: while( ! peek("'(?!')",1) ) { # ^ keep leading whitespace if( eat("''",1) ) { $str .= "'"; } else { swallow("[^']+",1,\$str,1); # fatal if no match # Can match to $Buf end ^ } } swallow("'",1); } else { swallow('"'); while( peek('[^"]',1) ) { while( peek('\\',1) ) { $str .= parse_escape(); } eat( qr{[^\\"]*}, 1, \$str, 1 ); } swallow('"',1,'',0,'Unclosed string',$start); } return $str; }