#do a for loop to make it go through the test for ($i=0; $i<=#@Comment; $i++) { #Do an if loop to go through and save the right thing if ($value == $Comm[$i]) { $Como = $Comment[$i]; } } #### for($i=0; $i <= if ($value==$Comm[$i]) { .... #### my $Como; foreach my $i (0..$#Comment) { $Como = $Comment[$i], last if $Comm[$i] == $value; } # ... and you should add error-checking: unless (defined $Como) { # do something here if we didn't find anything } #### # ... $Como = $Comment[$i], last if $Comm[$i] eq $value;