#!/usr/bin/perl -l use strict; use warnings; use Data::Dumper qw(Dumper); { my $boundary = 2; my $keyword = 'hallo'; my %table = map { $_ => join ' ', ($keyword, 'foo') x $_ } (0, 1, 2, 3, 4); my $does_match = sub { my ($str) = @_; my $occurences = 0; $occurences++ while $str =~ /(?:\A|\b)$keyword(?:\b|\z)/g; return { occurences => $occurences, match => ($occurences >= $boundary) ? 'yes' : 'no' }; }; print Dumper \%table; foreach my $often (sort { $a <=> $b } keys %table) { my $retval = $does_match->($table{$often}); print "occurences: $retval->{occurences}, match: $retval->{match}"; } }