use Scalar::Util (); # as advised by [choroba] my ($line, @arr); open my $fh, "<$ARGV[0]" or die "failed to open file $ARGV[0] for reading: $!\n"; my @check_fields = (6, 7, 8); my $line_counter = 0; LINE: while ($line = <$fh>) { $line_counter++; ### skip line if any of fields 6-8 are not numeric @arr = split /\s+/, $line; foreach my $i ( @check_fields ) { if ( ! Scalar::Util::looks_like_number($arr[$i - 1]) ) { # bad;this checks only for positive integers # (thanks Not_a_Number) # if ($arr[$i - 1] !~ /^\d+$/) { print STDERR "line num $line_counter: " . "1st problem field $arr[$i - 1]: " . "field num $i: " . "$line\n"; next LINE; } } ### the rest of your code }