Detect WAP browser and redirect to different url in Perl

Do you want to have the same url for your Web and Wap broswer? The following is the code to do so in Perl:

use CGI;

my $query = new CGI;

my @list=$query->Accept();

my $htmlsite="";
my $wmlsite="";

my $wml=0;
my $html=0;

foreach (@list) {
   $html=1 if /text\\/html/i;
   $wml=1 if  /wap/;

print $query->redirect($wmlsite)  if $wml==1;
print $query->redirect($htmlsite) if $html==1;
print $query->redirect($wmlsite);