Here's how I would modify the OP script:
#!/usr/bin/perl
use strict;
use warnings;
$/ = undef; # slurp-mode for input, just in case
while ( <> ) { # reads stdin or all file names in ARGV
s/\s+//g; # remove whitespace
tr/ACGTacgt//d; # remove all acgt
if ( length() ) { # anything left?
print "$ARGV bad content: $_\n";
} else {
print "$ARGV all clean!\n";
}
}
Using
while (<>) is good (even with slurp-mode input) because that way you can pipe data from any other process as input to the script, or you can put one or more file names on the command line (e.g. "*.txt").
When you read multiple input files in one run, putting "$ARGV" in the print statements tells you which files are good or bad.