Since I have seen no code or data, my response may be of no use at all. That being said, if your data looks anything like what is below and you are looking for the same nthfield in each line, this may work for you.
use strict;
use warnings;
my $data = join "" , <DATA>;
my @values = ();
(@values) = $data =~ /[P|U|Pu]\n\d+,(\d+)/gx;
print join '-', @values;
exit;
__DATA__
NP
1,2,3,4
U
5,6,7,8
Pu
9,10,11,12