eval { my $parser = Text::CSV::Simple->new; my @data = $parser->read_file($infile); }; # don't forget the semicolon! if ( $@ ) { if ( $@ =~ /the error you expect/ ) { unlink $infile; next FILE; } # unexpected error! die $@; }