http://www.perlmonks.org?node_id=716930


in reply to Regex question

This will work:

my ($number) = $data =~ /\d+/g;

The match operator returns the matched substrings only in list context, which is why your first code worked (assignment to an array). By using extra parentheses (like in my code above), you can turn a scalar assignment into a list assignment.

Update: You won't need the /g flag if you use capturing parentheses:

my ($number) = $data =~ /(\d+)/;