use PDL; my $sum = sum( minimum( cat($piddle1->copy->flat, $piddle2->copy->flat)->xchg(0,1) ) );