my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, isdst) = localtime(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