#!/usr/bin/perl -w use strict; my $text = qq|If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this is the place to ask. However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.|; # build lines hash my %lines; my $k=1; for (split(/\n/,$text)){ $lines{$k}=$_; $k++; } # score hash # put your words here, and the value for each my %score_guide = ( 'for'=>1, 'the'=>1, 'if'=>2, 'you'=>3, 'moguai'=>40 ); # this will hold key= line num, val= score my %score_results =(); # score each line for (keys %lines){ $score_results{$_} = score_line($lines{$_}); } # feedback for (keys %score_results){ print "line $_ score $score_results{$_}\n"; } sub score_line { my ($string)=$_[0]; # my $score=0; for (sort keys %score_guide){ while ($string=~s/\b\Q$_\E\b//i){ # corrected by ikegami $score+=$score_guide{$_}; } } return $score; } #### [leo@mescaline ~]$ perl scorelines.pl line 1 score 8 line 2 score 6 line 3 score 1 line 4 score 9 line 5 score 4 line 6 score 6