if ($content =~ /^(sub\s+\w+).+$/) { print "$1.\n"; # print sub name if ($content =~ /(#.+)$/) { print "$1\n"; # print sub comment } }