in reply to declaring same variable

samy1212,
Perhaps your problem is with scoping. If that's the case, you should take a look at the Tutorials section, in particular:
  • Coping with Scoping off site
  • Variable Scoping in Perl: the basics

    When you declare a variable - you are not only declaring it's name (what follows the leading sigil), it's type (scalar, hash, array, typeglob, etc), you are also declaring it's scope. When you declare a variable with my, you are restricting its scope to the nearest enclosing curly braces.

    Probably what you want to do is change its current value and not actually declare it again:

    my @array = qw(1 2 3); @array = qw(one two three) if $op eq 'alpha';
    Conditionally declaring a variable is generally considered a bad idea and can lead to problems down the road. So your code would change to:
    my @xxx; @xxx = qw(one two three) if $op eq 'numbers'; @xxx = qw(four five) if $op eq 'alpha'; @xxx = qw(six ten) if $op eq 'alp';
    Finally, if you want to use the same variable name, but in different scopes - that is perfectly acceptable:
    #!/usr/bin/perl -w use strict; hello('world'); goodbye('world'); sub hello { my $greeting = shift; print "hello $greeting\n"; } sub goodbye { my $greeting = shift; print "goodbye $greeting\n"; }
    I hope this helps - L~R