open (MYFILE, "< $dir_dump$file") || die "Could not read dump file\n"; while (){ $dumpbuf .= $_; } $dumpbuf =~ s/\s//gs; die "Not a valid file, Check output!" if $dumpbuf !~ m/\d/gs; #match one die "File contains only zeros, Check output!" if $dumpbuf !~ m/[1-9]/sg; #match two while ($dumpbuf =~ m/(\w)/gs) { print "==$1\n"; # prints characters after initial two matches }