#!/usr/bin/perl -w use strict; use Text::CSV_XS; my @files = qw(foo bar blah asdf); for my $file ( @files ) { if ( File_Type( $file ) ) { print "Do something with $file\n"; } } sub File_Type { my $file = shift; open (INPUT , '<' , $file) or die "Unable to open $file for reading : $!"; my $csv = Text::CSV_XS->new( {'sep_char' => ';'} ); while ( ) { next if $. != 2; chomp; if ( $csv->parse($_) ) { my @field = $csv->fields; die 'Incorrect number of fields' if @field != 4; return $field[2] =~ /^\d+$/ ? 1 : 0; } else { print "Unable to parse: ", $csv->error_input, "\n"; return 0; } } }