use strict; undef $/; my $text=; my @array=(); @array=$text=~m#void xxx \(void\)(\{[^\{\}]+\})#gs; $"="\n"; print "@array"; __DATA__ void xxx (void){ #inside function 1 } void xxx (void){ #inside function 2 } void xxx (void){ #inside function 3 }