#!/usr/bin/perl use strict; use warnings; my $line ="A\tB\tC\tD\t\t\t\t\n"; print "Test string line: $line"; print "Split without chomp: "; my @x=count_fields( $line ); check_for_null_elements(@x); print "Split _after_ chomp: "; chomp $line; @x=count_fields( $line ); check_for_null_elements(@x); exit; sub check_for_null_elements { foreach my $element (@_){ print "Empty element found\n" if ($element eq ""); } } sub count_fields { my ($line) = shift; my @x = split( /\t+/, $line); my $count = @x; print "$count fields.\n"; return (@x); }