#!/usr/bin/perl use strict; use warnings; my $usemod; # if you initialize `my $usemod = 0;`, then the BEGIN block's assignment to $usemod is overridden, which you don't want our $Registry; # this will be overridden by Win32::TieRegistry's export of $Registry if in Windows, but BEGIN { local $\ = "\n"; if( $^O eq 'MSWin32' ) { eval { require Win32::TieRegistry; Win32::TieRegistry->import( Delimiter => '/' ); $usemod = 1; } } } if ($usemod) { my $IEKey = $Registry->{'HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/Main/'}; print "IEKey = '$IEKey'\n"; } else { print "None of that stuff here\n"; }