in reply to hash reference

The smb.conf file is in a standard format popular with MS Windows and applications.for it. It will be no surprise that there is Config::IniFiles at CPAN to help parse them.

One More Really Round Wheel.

Update: That was too short. Here's a usage that gets you what you want:

use Config::IniFiles; my $smb = new Config::IniFiles( -file => '/etc/samba/smb.conf'); print join $/, $smb->Sections; # prints the section names
There are provisions for rewriting the file, but you'll have to take care of locking yourself. There is also a tied interface, but I'd be leary of that without built-in file locks.

After Compline,
Zaxo