I think the problem is that $
matches BEFORE a newline and ^
matches AFTER a newline (when using /sm), but you also need to consume the newline itself.
my $s = <<"__end__";
print "matched 1\n" if $s =~ m/^hubba$
print "matched 2\n" if $s =~ m/^hubba$ \n
Here only the second regex matches because in the first after the $ matches there is still a newline left and therefore the ^ does not match. You need to consume that in the regex as the second example shows.