jw2523, if you look at your data, your first line creates 6 dates that are stored in @dates. Later, you create a @flds array and generally you only put 3 nonempty entries into that array. The split leaves a few uninitialized variables in the array that lead to your errors. The following small change to your program will eliminate your error and give you cleaner output:
replace
for my $date (@dates_copy) {
print "$PID|$SID|",shift(@flds),"|$date\n";
}
with
for my $date (@dates_copy) {
my $field = shift(@flds);
$field = '' unless ( $field );
print "$PID|$SID|",$field,"|$date\n";
}