$filecontents =~ /.*?$blah\.([\w-]+)\(([^"]*)\)\s*;/; #not really sure what $blah is holding but #the [\w-] can replace your [0-9a-zA-Z_\-] character class #and \(([^"]*)\) is a greedy way of saying #anything inside of parens that is not a quote.