You could also use the $ENV{} hash to access the brower string. The user agent/browser info is stored in $ENV{HTTP_USER_AGENT}. Your code would change to :
my $browser = $ENV{HTTP_USER_AGENT};
I use this little program to see what is available on the different browsers that I test.
#!/usr/bin/perl
##
## printenv -- print the environment
##
print "Content-type: text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}