syntaxdef perl {

# whitespace
/\s+/m : ;

# comment
/#.*?$/m : {
    region {
        type=comment;
        index=prose;
        findlinks=true;
    }
}

# reserved words
/(__FILE__|and|end|in|or|self|unless|__LINE__|begin|defined\?|def|ensure|module|redo|super|until|\
BEGIN|break|do|false|next|rescue|then|when|END|case|else|for|nil|retry|true|while|\
alias|class|elsif|if|not|return|undef|yield)\b/ : {
    region {
        type=keyword;
    }
}

# numbers
/ [+-]?
  (  0[xX][A-Za-z0-9_]+
   | 0[bB][01]+
   | [0-9_]+ (.[0-9]+)? (e[+-]?[0-9]+)?
  )
/x : {
    region {
        type=numeric;
    }
}

# strings
/"/ : {
    context {
        /\\./: ;
        /\{.*?\}/: ;
        /$/m : exit;
        "\"" : exit;
    }
    region ${ALL} {
           type=string;
    }
}

/'/ : {
    context {
        /\\./: ;
        /\{.*?\}/: ;
        /$/m : exit;
        "'" : exit;
    }
    region ${ALL} {
           type=string;
    }
}


# here-docs, can be like <<EOF or << "EOF"
/<<((\w+).*?(^\2$)|\s+"([^"]*)".*?(^\4$)|\s+'([^']*)'.*?(^\6$))/sm : {
    region {
        type=string;
        findlinks=true;
    }
}

# symbols
/:[a-zA-Z_][a-zA-Z0-9_]*/ : {
    region {
        type=symbol;
    }
}

# names
/(@@?)?[a-zA-Z_][a-zA-Z0-9_]*/ : {
    region {
        type=identifier;
    }
}
# global names
/\\$([a-zA-Z_][a-zA-Z0-9+]*|[!_]|-.)/ : {
    region {
        type=identifier;
    }
}


# regex // or %r{} style
/
   \/(
     (\\\/|[^\/\n\r])*?
     |
     (\\\/|[^\/]){0,100}
   )\/
   |
   %r\{(
     (\\\/|[^\/\n\r])*?
     |
     (\\\/|[^\/]){0,100}
   )\}
/x : {
    region {
        type=string;
    }
}


}