Everyone told you how to do it right, but no one told you what you were doing wrong.
my $xcltime = "19:45:34"; # It should print 7:45 PM my $xcltime2 = "23:35:14"; # It should print 11:35 PM if (($xcltime =~ /(\d{1,2}):(\d{1,2}):(\d{1,2})/) || ($xcltime2 =~ /(\ +d{1,2}):(\d{1,2}):(\d{1,2})/)) {
You should probably do a loop over both $xcltime and $xcltime2, to make sure BOTH of them get the treatment.
my $h1=$1;my $m2=$2; my $s3=$3; if ($h1 =~ /13||14||15||16||17||18||19||20||21||22||23||24/) {
You're confusing Perl's "OR" operator || with the regex's alternation symbol |. When you use a||b in a regex, you're saying "match 'a' or nothing or 'b'".

There's also no point in saying "if $str matches /foo/, substitute 'bar' for /foo/". Just say "substitute 'bar' for /foo/", and if any matches are found, they'll be changed. The idiom s/a/b/ if /a/ is pointless.

$h1=~s/13/1/; $h1=~s/14/2/; $h1=~s/15/3/; $h1=~s/16/4/; $h1=~s/17/5/; $h1=~s/18/6/; $h1=~s/19/7/; $h1=~s/20/8/; $h1=~s/21/9/; $h1=~s/22/10/; $h1=~s/23/11/; $h1=~s/24/12/;
And there's no reason to use regexes here. $h1 is just a number now. This logic should be written as
my $pm = 0; # assume AM if ($h1 > 12) { $pm = 1; $h1 -= 12; }
_____________________________________________________
Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

In reply to Re: Time transformation by japhy
in thread Time transformation by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.