in reply to regex to split a line
This should satisfy your requirements, assuming you didn't leave any tricky stuff (like leading whitespaces) out of your OP. Either way, you might want to make sure the regex matched before assigning anything. I assumed that there were a variable number of spaces between the username and the data, since the OP didn't contain a tab.
If you had a %users hash, you could then do $users{$name} = $data.use warnings; use strict; my $line = 'username Real Name|email@gmail.com|2|30|'; my ( $name, $data ) = $line =~ m/^(\S+)\s+(.+)$/; print "[$name][$data]";
HTH
|
---|