All my functions are form ( at least one underscore ) "aa_yy_zz_ttt (" and i should find those from file. Each line can also have several functions.

why this :

$str =~ /^[a-z]+\_{1,}+\w+\s{0,}\(/; doesn't work to get the exact match..

e.g

When input value is $str =" return ( *( int* ) MACRO_FUNCTION("; -> output is the same as input, which is wrong -> it should notice that return doesn't have underscore. And it should return only "MACRO_FUNCTION(" and not " return ( *( int* ) MACRO_FUNCTION("

$str =" main_sub_function ("; - this should be OK to be found, but it doesnt work for me.

You are not saying enough about how you use your regex, but, clearly, '/^[a-z]+\_{1,}+\w+\s{0,}\(/' cannot match the expression " return ( *( int* ) MACRO_FUNCTION(" for several reasons.

To start with, your regex starts with '/^[a-z]+', meaning that a match has to start with one or several lower case characters. But your expression starts with a space, not a [a-z] character, so no match.

Even if you remove the '^' at the beginning of the regex, then it might start a match anywhere in the string. But it still will not match anything in your expression, because it looks for a bunch of lower case characters, followed by one of several '_', followed by a bunch of word characters. That will not match "MACRO_FUNTION" because MACRO is not in lower case.

Concerning the " main_sub_function (" expression, it will again not match because of the leading space in the expression, whereas your regex says the string has to start with a [a-z] character, not a space. Again, if you remove either the leading space in the expression or the leading '^' in the regex, this will still not match because your regex declares two groups of letters separated by one or several '_', not three groups of letters semarated each by a '_' character.

The changes I made: - No need for the '\' before the _, as '\' is not a special character for regexes; - No need for the {1} quantifier after the "_", just useless here, as if you don't purt one, the regex will look for one occurrence; - I have added a pair of parentheses to enclose the whole regular expression, so that $1 captures the whole thing rather than only the first part between the first set of parens. Only this 3rd change was really necessary, the other two are just cosmetic simplifications of what you had, with no effect on matched results.

BTW, speaking of simplifications, {1,} could be replaced by '+' and {0,1} by '?', so that the regex can be further simplified into: