The match operator in list context returns the captured texts if there are any, so all you need to do is add a capture (parens) around the bit you want returned.
my ($blocks) = $string =~ /(?<=blocks=)([^$]*)/;
print "$blocks\n";
The lookbehind is just slowing you down.
my ($blocks) = $string =~ /blocks=([^$]*)/;
print "$blocks\n";
We should check if the match actually succeeded.
if ( my ($blocks) = $string =~ /blocks=([^$]+)/ ) {
print "$blocks\n";
}
But I'm confused as to why you're matching characters other than the dollar sign. You probably meant to match characters other than the newline.
if ( my ($blocks) = $string =~ /blocks=([^\n]+)/ ) {
print "$blocks\n";
}
Given that you aren't using /s, that can also be written
if ( my ($blocks) = $string =~ /blocks=(.+)/ ) {
print "$blocks\n";
}
Personally, I'd use
if ( my ($blocks) = $string =~ /blocks=(\S+)/ ) {
print "$blocks\n";
}
To get all matches, it's just a question of using /g.
for my $blocks ( $string =~ /blocks=(\S+)/g ) {
print "$blocks\n";
}