#!/usr/bin/perl -w print "Enter the name of your file, ie myfile.txt:\n"; my $val = ; chomp ($val); my $cnt=0; open (HNDL, "$val") || die "wrong filename"; while ($val = ) { while ($val =~ /\bchr1\b/ig) { ++$cnt; } } print "Number of instances of 'chr1' found: $cnt\n\n";