Bibbity Bobbity *foo::bar (baz) { #### $ cat 1070117.pl #!/usr/bin/perl use strict; use warnings; my $regex = qr/(.*?)\n((?:\w+\*?\s+)+)(\*?[:\w]+\s*)\s*\((.*?)\)(\s*\{)/; my $text = "foo\nfizzy bar::baz(a b) {\nblarf\n"; if ($text =~ $regex) { print "Matched! $1, $2, $3\n"; } $ perl 1070117.pl Matched! foo, fizzy , bar::baz