use strict; my $sql = <<'--SQL--'; # this is a comment $a = "simple string"; $b = "string and comment"; # comment $c = "string with # thing"; # comment with "string" $d = "very hard" # dasdas . "to do"; --SQL-- use HOP::Lexer 'string_lexer'; my $lexer = string_lexer( $sql, [ STRING => qr/"[^"]+"/ ], [ COMMENT => qr/#[^\n]*/ ], [ SPACE => qr/\s+/, sub {} ], ); # (continues like the others...)