Try regex
sub test { my $str =shift; if(length($str)==11) { $str=~ m/^(\d(\d{6})\d+)$/; print"$1 $2\n"; } else { $str=~ m/^((\d{6})\d+)$/; print"$1$2 $2\n"; } } my $a='01234567890'; my $b ='15556667777'; test($a); test($b);
Output
01234567890 123456
15556667777 555666
In reply to Re^2: Negative Index with "substr" Not Working
by grasshopper!!!
in thread Negative Index with "substr" Not Working
by he204035
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |