in reply to pattern matching

The comments so far have to do with whether or not there is a "\n" at the end of tail.
Here are some ways to make your regex insensitive to that:
#!/usr/bin/perl use strict; use warnings; # modified code from [Grandfather] my $tail = ".D(next_out_en), .CP(n16), .CDN(n48), .Q(\n"; my $tail2 = ".D(next_out_en), .CP(n16), .CDN(n48), .Q("; print "MatchedA: \$1 '$1', \$2: '$2', \$3: '$3'\n" if $tail =~ /^\s*(.+)\s+\.\s*CP\s*\(\s*(\S+)\s*\)\s*\,\s+(.+)\s*$/ +i; print "MatchedB: \$1 '$1', \$2: '$2', \$3: '$3'\n" if $tail2 =~ /^\s*(.+)\s+\.\s*CP\s*\(\s*(\S+)\s*\)\s*\,\s+(.+)\s*$ +/i; print "MatchedC: \$1 '$1', \$2: '$2', \$3: '$3'\n" if $tail =~ /^\s*(.+)\s+\.\s*CP\s*\(\s*(\S+)\s*\)\s*\,\s+(.+)\s*/i +; __END__ Prints: MatchedA: $1 '.D(next_out_en),', $2: 'n16', $3: '.CDN(n48), .Q(' MatchedB: $1 '.D(next_out_en),', $2: 'n16', $3: '.CDN(n48), .Q(' MatchedC: $1 '.D(next_out_en),', $2: 'n16', $3: '.CDN(n48), .Q('
First, notice that the $ anchor in a regex will ignore the line ending if it even exists.

Second, notice that since "\n" is one of the white space characters. You can simply remove "\n" from the regex and it won't matter whether the "\n" character(s)are there or not. This is shown as option C.