#!/usr/bin/perl use strict; my $source = "test data"; if ( @ARGV ) { $source = shift; open( DATA, '<', $source ) or die "$source: $!\n Usage: $0 [data.file]\n"; } my @inputs; while () { chomp; push @inputs, $_; } # do some stuff with @inputs, as you see fit... e.g. my $sum; my $input_list; for my $value ( @inputs ) { $sum += $value if ( $value =~ /^-?[\d.]+$/ ); $input_list .= " $value"; } printf( "There were %d values in '$source': %s\n The numeric sum is %f\n", scalar @inputs, $input_list, $sum ); __DATA__ 5 10 non_numeric 15 20