#!/usr/bin/perl use warnings; use strict; my $in_filename = shift @ARGV; my @extra_parms = @ARGV; sub usage { print "Usage:\n Searches for selected 'sentences' in input file\n"; print " A sentence ends with a period(.) or could be the\n"; print " end of line '\\n'\n"; # other text to expain what "rules are goes here.... # give an example of the command. print " Example: mysearch infilename\n\n"; print " The program will prompt user for the search terms.\n"; exit(1); #this is an error exit (non-zero return value) } # The very basic "sanity" checks to display the usage() message. if (!defined($in_filename) or @extra_parms>0 or $in_filename =~ /^(-)?\?/ or $in_filename =~ /^\s*-(-)?h(elp)?/i) { usage(); } if (! -e $in_filename) { print "Error! input file name: $in_filename does not exist\n\n"; usage(); } print "Enter search parameter(s), one per line or end\n"; my $input; my @search_tokens; while ( (print "search for: "), $input=, $input !~ /^\s*END\s*$/i) { next if $input =~ /^\s*$/; # re-prompt on a blank input line $input =~ s/^\s*//; # delete leading spaces $input =~ s/\s*$//; # delete trailing spaces if ($input =~ /^\S+\s+\S+/) { print "Error! Only one search term per input line!\n"; next; } # Note: here tr// counts the number of characters which are not # in the set, without modifying the $input variable. if ($input =~ tr/A-Za-z0-9_//c) # must be legal characters # for a filename! { print "Error! Illegal character! only A-za-z0-9_ allowed!\n"; next; } if ($input =~ /^\d/) # must be legal characters for a filename! { print "Error! Token cannot start with a number!\n"; next; } push (@search_tokens, $input); } if (@search_tokens==0) { print "Error! No search tokens entered..exiting..\n"; exit (2); # another error exit with error code 2 } # For debugging, dump the tokens back out print "\n"; #just a space line print "Search Terms are:\n"; foreach my $token (@search_tokens) { print "token=\'$token\'\n"; } __END__ Get the above working and tested, then move on the next section of the program. You can make a separate test program that just Hard codes the $filename and @search_tokens. Get that working, then move on to another step.