while (<DATA>) { chomp; my ( $letters, $numbers ) = ( /^(\D+)(\d+)$/ ); print "$letters\t$numbers\n"; } __DATA__ art1012387 stuff458353 other432610
Now that I stop to think about it, you should check if the match is successful and if you really have letters up front. Changing that makes the following while loop:
while (<DATA>) { chomp; if ( /^([a-zA-Z]+)(\d+)$/ ) { my ( $letters, $numbers ) = ( $1, $2 ); print "$letters\t$numbers\n"; } else { print "No match: $_\n"; } }
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re: How do I split a string which has letters then numbers?
by Ovid
in thread How do I split a string which has letters then numbers?
by lucasdmc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |