Take a look at Intersection().
For example:
Calculate a field in the line feature class:
var polygons = FeaturesetByName($datastore, "TestPolygons")
var polygon = First(Intersects(polygons, $feature))
if(polygon == null) { return null }
var i_line = Intersection(polygon, $feature)
return Length(i_line)
Label the line with this expression
`line: ${Round(Length($feature))} meters\nintersection: ${Round($feature.DoubleField)} meters`
Result:
Have a great day!
Johannes