my $x = 'abc12345'; my $length = length (($x =~ /(\d+)$/)[0]); # returns 5