in reply to Time transformation

I'm not understanding how your variables $xcltime and $xcltime2 are related. It looks like you're trying to set them both at once, to the same thing. Unless there's some weird dependency, you'd probably do best to extract out the time manipulation code into a subroutine, so the heart of your program can be just
$xcltime=convert_time($xcltime); $xcltime2=convert_time($xcltime2);
or similar. Then you just create a subroutine to do the conversion. I'd probably write it like this
sub convert_time{ my ($time)=shift; my ($h, $m, $s) = $time =~ /^(\d\d?):(\d\d?):(\d\d?)$/; my ($suffix); if ($h > 12){ $h-=12; $suffix=" PM"; } elsif ($h == 0) { $h = 12; $suffix=" AM"; } else { $suffix=" AM"; } return "$h:$m:$s$suffix"; }
Another issue is that your code inserts no space for AM, but an html nonbreaking space for PM. I've inserted the space in both cases, but you could change that if you really wanted to.

I've also included a fix for if the time is "00:15:17" or such, converting it to "12:15:17 AM".