or download this
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, isdst) = loca
+ltime(time);
my $ampm=$hour>11 ? 'PM' : 'AM'; # day or night
$hour%=12; # put it in the range 0..11
$hour=12 unless $hour; # convert 0 to 12
print "$hour$ampm"; # print it out