use strict; use warnings; my (@numbers, $handle); open ($handle, "c:/documents and Settings/david price/my documents/cingular.txt") || die "cannot open: $!"; @numbers = <$handle>; close ($handle); for (@numbers) { if (index($_, '9432') != -1) { print "match found\n"; } else { print "match failed\n"; } } #### open (CINGULAR, "c:/documents and Settings/david price/my documents/cingular.txt") || die "cannot open: $!"; # USE VARIABLES FOR FILE HANDLES INSTEAD OF NAMED FILE HANDLES @number=; # DECLARE A SCOPE FOR ALL VARIABLES. my @number=; would be better close (CINGULAR); $count=0; # SAME while ($count<100) { # IF YOU WANT TO LOOP THROUGH AN ARRAY, USE SOMETHING LIKE: # for (my $c = 0; $c <= $#number; $c++) { print $number[$c]; } # for (0..$#number) { print $number[$_]; } # for (@number) { print $_; } # foreach (@number) { print $_; } # $#number is the address of the last item in the array. # $_ is the default input / output variable. if (@number=~[/^9432$/g]) { # PROPER SYNTAX IS if ($number[$count] =~ /9432$/) { # The g flag is used for multiple matches; ^ and $ are only used together # if you want a match at both ends - in other words, an exact match. # I don't know what the brackets were for. print "match found"; } else { print "match failed"; } $count++; # THIS IS FINE. HOWEVER, YOU COULD HAVE SAVED A STATEMENT BY DOING: # while ($count++ < 100) { }