in reply to greping inside a file

Take a look at Tie::File, and by using that you can easily turn the file into an array.

Then go thru the small array you have, and use regexp, or just split on \s to get the keys and values.

Hope the following sample can get you started.

use Tie::File; use Data::Dumper; use strict; use warnings; print Dumper(foo('profile.txt')); sub foo { my (@a, %result); tie @a, 'Tie::File', shift; foreach (@a) { /(.*?)\s+(.*)/g; $result{$1} = $2 if (($1 eq 'firstname') or ($1 eq 'lastname') + or ($1 eq 'middlename')); } return \%result; }