while () { my $pw = @chars[map{rand @chars} (1..17)]; } unless ($_ ne my $usedpw) { print "Your unique ID is: $pw\n"; } my $pw; open(USEDPW, "> $usedpw") or die "crap on me for writing $!"; flock USEDPW, 2; print USEDPW "$pw\n"; #### #notice we declare it OUTSIDE the loop my $pw; while () { $pw = @chars[map{rand @chars} (1..17)]; } unless ($_ ne my $usedpw) { print "Your unique ID is: $pw\n"; } open(USEDPW, "> $usedpw") or die "crap on me for writing $!"; flock USEDPW, 2; print USEDPW "$pw\n";