my @contents = grep { /^[Bb].+.txt$/ } @cont; #### /^[Bb].+\.txt$/ #### open(FILE, "<$logfile"); # specify read explicitly with < print "$logfile:\n"; print while(); close(FILE);