I've never used perl. What's the difference?
$foo =~ /regex/
$result = $foo =~ /regex/
if ($foo =~ /regex/) {whatever;}
while (/regex/) {whatever;}
The captures ($1, $2, etc.) are global and usable wherever you need them.In this particular case the default is that $ matches the end of a string without a newline but you can include it anytime you need to:
$foo =~ /regex$/ # end of string without newline
$foo =~ /regex$/m # end of string with newline