in reply to regular expression

How about

use strict; use warnings; my $str = '4512872356698'; my $len = length $str; substr($str, 6, $len - 10) = 'X' x ($len - 10); print "$str\n";

Using lvalue substr for good effect.

Replies are listed 'Best First'.
Re^2: regular expression
by Anonymous Monk on Feb 15, 2012 at 12:44 UTC

    I have to show only fist 6 and last 4 digits in between there can be any number of characters

        Slight variation so you don't need the length:

        substr($str, 6, -4) =~ s/./X/g;

        Inspiring. Subtracting the sum of the value of the length of the first and last visible digits to establish the variable length of the middle section. ++