use strict; use warnings; my $xcltime = "00:45:34"; # It should print 12:45 AM my ($h, $m) = split /:/, $xcltime; my $ampm = $h < 12 ? 'AM' : 'PM'; $h = ($h % 12) || 12; print "$h:$m $ampm"; # prints 12:45 AM