grep { print scalar (@params = /^\s*(?:(?:public|private|protected)\s+)?\w+\s+\w+\s*\(([^,]+)(\,[^,]+)*\)/g);} <>; #### perl test.pl FILENAME #### grep { print scalar # print the number of items matched (@params = /^ # any whitespace at start of line \s* #optional access modifier (?:(?:public|private|protected)\s+) # return type and method name \w+\s+\w+\s* \( # params separated by commas ([^,]+)(\,[^,]+)* \) # don't really need m or s # since only one line is read at a time, # but I find it a good habit to always # use them /gxms); } <>; # read from keyboard or the file(s) provided on command line