if you were to use Net::IRC, you can add event handlers. All you'd need to do is create a handler to handle public events (the events that happen in the room window). Something like this:
#!/usr/bin/env perl
use Net::IRC;
my $irc = new Net::IRC;
my $conn = $irc->newconn(Server => 'irc.freenode.org', Port => '6667', Nick => 'Chuck-Norris', Ircname => 'Yo-Momma!');
sub on_public {
my ($conn, $event)= @_;
my $text = $event->{args}[0]; #what the person said.
my $nick = $event->{nick}; #the person's nick name.
if ($text =~ m/\!server/)
{
#then you would grab the text you wanted from $text here and save it.
}
}
$conn->add_handler('public', \&on_public);
$irc->start;
Ofcourse the code above will connect to irc.freenode.org, but it will not join a room, for that you need to setup a on_connect handler, then send a join command.
You could grab the text you wanted a few different ways. you could use the function substr if you know the total length of the string you are working with (which can be obtained from the function length()). Also i am sure there is a way to get the text you need form the string using a regular expression. It's all really up to you and what your comfortable with.