in reply to can split() use a regex?

As other monks have mentioned, you can certainly use a regex in split. If you want to divide a string into parts based on field length rather than a specific delimiter (pattern), however, you can also use unpack.

use strict; use warnings; my $string = '1234 this is the remaining string'; # A4 = take the first 4 ASCII characters # x = skip the next byte # A* = take all remaining ASCII characters my ( $num, $text ) = unpack( 'A4xA*', $string ); print "[$num][$text]\n";
Prints:
[1234][this is the remaining string]

pack and unpack can be confusing. Pack/Unpack Tutorial (aka How the System Stores Data) is a great tutorial to get you started, and Super Search will help you find other references.

Update:
unpack significantly outperforms both split and the regex approach, as shown below (I used BrowserUK's code in Re: can split() use a regex? for the other two approaches):

use strict; use warnings; use Benchmark qw( cmpthese ); my $string = '1234 this is the remaining string'; cmpthese( -5, { unpack => sub { unpack( 'A4xA*', $string ) }, regex => sub { $string =~ m[(\d+)\s+(.*)$] }, split => sub { split( /(\d+)\s+/, $string, 2 ) }, } );
Results:
Rate split regex unpack split 789472/s -- -44% -70% regex 1422218/s 80% -- -45% unpack 2594984/s 229% 82% --

HTH