print "Letter? "; my $input = ; # get rid of line ending chomp($input); # take the first character and escape it if it is a possible metacharacter my $letter = quotemeta substr $input, 0, 1; open DATA, 'books.txt' or die "Couldn't open books.txt: $!"; my @data = ; close DATA; foreach my $data (@data) { print $data if $data =~ /^$letter/i; }