use strict; undef $/; while () { print; / ( #Start capture ( #Start Sub descript header '-{20,} #start '------ delimiter (\n'[^\n]*?)+\n #middle of header '-{20,}\n #end '------ delimiter )? #End Sub header (optional) (Private\s|Public\s|Friend\s)? #Scope (optional) (Static\s)? #Static (optional) (Sub\s|Function\s) #Sub or Function (mandatory) (\w+) #Sub name ( #Start Params \( #Left paren ([^\)])* #Optional params inside \) #Right paren )? #End Params (optional) \s+ #Space ((?!Lib\s)) #no Lib on line ([^\n]+) #more stuff on same line unless "Lib" (.*) #and the rest of the file ) #End capture /sx; }; __DATA__ Private thingy as String Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" '----------------------------------------------------------- ' This is a header '----------------------------------------------------------- Private Function foo(byVal x as Long, byVal y as String) as Integer