in reply to
Regular expression quantifiers and the /gsmx modifiers
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.
Consider:
use strict;
my $s = <<"__end__";
hubba
bubba
__end__
print "matched 1\n" if $s =~ m/^hubba$
^bubba$/smx;
print "matched 2\n" if $s =~ m/^hubba$ \n
^bubba$/smx;
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.