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

Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I know I'm probably going to slap my forehead after I get a response for this but...

I've got a very simple regex which I want to just pull sequential digits out of a filename which is passed in - e.g. sfytd13.txt should return 13.

I'm using the following code:

use strict; my $file = 'file013.txt'; my $sk = $file =~ m/\d+/; print $sk;

Very simple, but the problem is that I'm only getting the '1' back. I realize that if I use parthensis matching $1 will return '013' but I'm curious as to why my code doesn't return 13.

My understanding is that \d+ is going to match a digit followed by any number of digits until I hit a non-digit. What am I missing here? Is something getting clobbered in the assignment?

Thanks in advance!

There is no emoticon for what I'm feeling now.