#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $datei = 'test.txt'; sub prepareLine { my $line = shift; chomp($line); $line = lc($line); $line =~ s/\W+|\d|_/ /g; $line =~ s/^\s+|\s+$//; return $line; } sub getCount { my $str = shift; my @arr = @_; my $count = 0; for my $i (@arr) { if ($i eq $str) { $count++; } } return $count; } my $fh; open($fh, "<", $datei); my @zeilen; my $line; my $i; my $count; while ($line = <$fh>) { $line = prepareLine($line); my @splitted = split(/ /, $line); my %hash; for $i (@splitted) { $count = getCount($i, @splitted); $hash{$i} = $count; } push(@zeilen, \%hash); } close($fh); print Dumper(\@zeilen);