Here's how:
$_="ab123.ab456cd.78";
($val = (split(/\./))[1])=~ s/\D//g;
print $val;
(I took the liberty of using the implicit $_
in split
, and adding the /g
tag to the s///
because removing one non-digit from the front didn't make much sense.)
Now you know this, don't do it. It's not clear to read, it doesn't show your intensions, and it's horrible. Much clearer is:
$val = (split /\./)[1];
$val =~ s/\D//g;
Code isn't just written for the computer. It's written for people to read in order that they can later modify it. If you don't write nice code for the next guy (who could be you in 2 months time), the next guy will have a horrible time figuring out what you did.