Browser Detection by PERL

I am enjoying PERL a lot. I am seeing everything new in PERL. I want to share interesting and important PERL stuffs through my blog.

Here is a PERL subroutine that detects whether the browser is Firefox or NOT.

sub is_firefox {
my $agent = ‘’;
$agent = $ENV{”HTTP_USER_AGENT”} || ‘’;
if (length($agent) && $agent =~ m/firefox/si) {
return 1;
return 0;

Enjoy PERL, the scripting pioneer.



4 thoughts on “Browser Detection by PERL

  1. PERL is short for ” Practical Extraction and Report Language”.
    If I write “Perl”, it does not highlight that it’s abbreviated from something. Well, it’s my way. Many ones write “perl” or “Perl” or “PERL”.



  2. thanks for your code…

    but I have a little problem

    if you browse my website using firefox and then use another browser on same computer to visit my website then perl script detect the browser as firefox until you vist the page once and then press F5

    this works on localhost but on remote computer not works…

    any help appreciated


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.