Remove the $ sign at the end of the regex.
On the line after ref = com there is the id=<id> assignment, which the regex fails to match.
if (m/^(.*) UTC.*ref .*? = (\d+)/
Should fix it.
I recommend debugging such bugs in the perl debugger perldebtut.
Scroll stepwise through the Script via command 's' and print conditions captured variables via command 'p'.
If the match is not as expected try to narrow the bug down with simpler regexes / conditions.
Removed misleading advice. The .*? should jump the regex right to the id assignment.