This does seem like wee bit more trouble than its worth when
Date::Format will make short work of it. But.. sigh you may have a good reason not to use a 'pm'. Hopefully that reason is not laziness because in this case it is not a programmatic virtue. A few minutes with Date::Format will allow you date and time laziness for a life time. A few more minutes spent with Date::Manip and Date::Calc will let you deal with time() while sitting under a palm tree sipping Tequila Sunrises.
mitd-Made in the Dark
'My favourite colour appears to be grey.'