while () { if (/^ # Matches line start \s* # None or many spaces (?:public|private)? # Matches 'public', 'private' or none (packages) \s+ # One or many spaces (?:\S+) # Matches one or more non spacing chars (variable type) \s+ # One or many spaces (?:\S+) # Matches one or more non spacing chars (method name) \s* # None or many spaces \( # Literal '(' (.*) # Matches everything \) # Literal ')' \s* # None or many spaces $ # Matches end of line /x) { print $1, "\n"; } } __DATA__ public void check1(String str, Integer i) { }