for my $rec ( @recs ) { my @rec = split(/:/,$rec); next unless @rec; push (@goodrecs,$rec) if( $rec[$n] =~ /$pattern/ ); }