in reply to given time1a and b how much is in time2a and b

Sounds like interval arithmetic:

use List::Util qw( min max ); sub overlap { my @intervals = @_[0, 1]; my $left = max( map $_->[ 0 ], @intervals ); my $right = min( map $_->[ 1 ], @intervals ); return max( 0, $right - $left ); }
Just turn the 3rd and 4th args to seconds relative to the epoch, and use the above function, with the intervals passed as array refs [ $time1a, $time1b ], [ $time2a, $time2b ].

the lowliest monk