#!/usr/bin/env perl use strict; use warnings; sub not_only_atgc { my $sequence = shift; if ( $sequence =~ /[^atgc]/i ) { return 1; } return 0; } my %test_criteria = ( "Must not be 19 characters long" => sub { return 1 if (length($_[0]) != 19); }, "Must contain other than atgc" => \¬_only_atgc, ); my $lineno = 0; # Read one line at a time open( my $fh, "data.txt" ) or die "$!"; LINE: while ( my $line = <$fh> ) { $lineno++; my @words = split /\s+/, $line; print "Processing line $lineno interested in $words[2]\n"; TEST: for my $criteria_check ( keys %test_criteria ) { if ( $test_criteria{$criteria_check}->( $words[2] ) ) { # Test returned 1 } else { print "Fail: $criteria_check\n\n"; next LINE; } } ## All checks have passed after this line ## print "$words[2] passes all criteria\n\n"; }