use Getopt::Long; # or Getopt::Std, which might be easier to grok. #### my @thresh = ( 1000, 4000, 7000, 10000 ); my @bins; while () { my $val = ( split )[10]; next unless ( $val =~ /^\d+$/ ); my $i; for $i ( 0 .. $#thresh ) { last if ( $val < $thresh[$i] ); } $bins[$i]++; } #### my @thresh = ( 1000, 4000, 7000, 10000 ); my @bins; while () { my $val = ( split )[10]; next unless ( $val =~ /^\d+$/ ); my $i = 0; while ( $i < @thresh and $val > $thresh[$i] ) { $i++; } $bins[$i]++; }