请教:提取字符串的问题

请教:提取字符串的问题

我想把"cat /proc/version"命令中的有效字符提取出来,比如:
在ubuntu上,
$ cat /proc/version
$ Linux version 2.6.24-16-generic (buildd@palmer) (gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)) #1 SMP Thu Apr 10 13:23:42 UTC 2008
我想提取的是:
$kernel_version = "Linux version 2.6.24-16-generic"
$gcc_version = "gcc version 4.2.3"
$pub_version = "Ubuntu 4.2.3-2ubuntu7"

如何做到这一点?并且希望这个程序在任何linux版本上都应该通用。谢谢!
Using regexp!
Sample code:

QUOTE:
use strict;
open F, '/proc/version' or die $!;
my $line = <F>;
close F;
#print $line;
# read it as 3 parts
if ($line =~ m/^linux (.+)\s\(gcc (.+)\)\s\#(.+)$/i) {
    my ($ver, $gcc, $ts) = ($1, $2, $3);
    print "Linux     : ", $ver, "\n";
    print "gcc       : ", $gcc, "\n";
    print "Timestamp : ", $ts, "\n";
}
# to process more details is your task

这是我自己写的,看上去有些丑陋

#! /usr/bin/perl

use strict;
use warnings;

sub check_linux_ver
{

    my $info = `cat /proc/version`;
    my $ver = '';
    my $gcc = '';
    my $pub = '';

    if ($info  =~ /^(\S+) (\S+) (\S+)/) {
        $ver = "$1 $2 $3";
    }

    if ($info =~ /gcc (\S+) (\S+)(.*)\((.*)\)\)/) {
      $gcc = "gcc $1 $2";
      $pub = "$4";
    }

    print "$ver\n";
    print "$gcc\n";
    print "$pub\n";
}

&check_linux_ver;
my ($ver, $tmp1, $tmp2, $gcc, $pub) = (/[^)(]+/g)