A \@nick (\w+) $bot_nick = $1; print "NICK :$bot_nick\n"; open(NICK_OPEN,"config"); my @temp_nick = ; close NICK_OPEN; open(NICK_WRITE,">config"); foreach(@temp_nick) { if (/bot_nick/) { print NICK_WRITE "\$bot_nick=\"$bot_nick\";\n"; } else { print NICK_WRITE "$_"; } } close NICK_WRITE;