#!/usr/bin/env perl -l use strict; use warnings; my $f1 = 'static gboolean g::ber_read(wtap *wth, int *err)'; my $f2 = 'static void ber_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size)'; for ($f1, $f2) { print "Function: $_"; /([:\w]+\([^)]*\))/m; print "Captured: $1"; # if you want multi-line reduced to single-line: (my $no_newlines = $1) =~ y/\n/ /; print "Lines joined: $no_newlines"; }