sub confighandler { chomp(my $cmd = shift); chomp(my $option = shift); chomp(my $value = shift); open CONFIG, "<","aircracker.conf" or die $!; my @cfgdata = ; close(CONFIG); if (($cmd eq 'read') && ($option)) { foreach (@cfgdata) { if ($_ =~ m/<$option>(.+)<\/$option>/) { return $1; } } return ("Error: not an option: $option"); } elsif (($cmd eq 'write') && ($option) && ($value)) { my @newcfg; foreach (@cfgdata) { $_ =~ s/<$option>.+<\/$option>/<$option>$value<\/$option>/; push(@newcfg, $_); } open NEWCONFIG, ">","aircracker.conf" or die $!; print NEWCONFIG @newcfg; close(NEWCONFIG); return ("Config saved"); } else { return ("Error: read or write?"); } } confighandler("write","daemon","2");