in reply to Oft encountered regex problem

This should do what you want.

#!/usr/bin/perl -w use strict; use Data::Dumper; my $first = <<'END'; name is Doug eyes: brown email at bill@hotmail.com END my $second = <<'END'; name is Fred eyes: black era: prehistoric email at fflinstone@hotmail.com END sub parse { my $text = shift; my %info = (); while ($text =~ / ^ # start of line (\w+) # a word [:\s] # colon or space .* # anything \s # a space (\S+) # a sequence of non spaces $ # till the end of line /xmg) { $info{$1} = $2; } return \%info; } for ($first, $second) { print Data::Dumper->Dump([parse($_)], ['info']),"\n"; } __END__ $info = { 'eyes' => 'brown', 'email' => 'bill@hotmail.com', 'name' => 'Doug' }; $info = { 'eyes' => 'black', 'era' => 'prehistoric', 'email' => 'fflinstone@hotmail.com', 'name' => 'Fred' };

You can assign the result from parse() to a hash reference and eventually build the structure that suits your needs best.