#!/usr/bin/perl
use strict;
use warnings;
while(<>) {
s/\b(\w+)\b/&wortspiel($1)/ge;
print;
}
sub wortspiel {
if ($_[0] =~ m/\b(\w)(\w+)(.)\b/) {
my @letters = split(//, $2);
shuffle (\@letters);
return $1.join ('', @letters).$3;
}
else {
return $_[0];
}
}
sub shuffle {
# vgl. O'Reilly, Perl-Kochbuch dt., 1. Auflage, 4.17, fisher-yates-shuffle
my $array = shift;
my $i;
for ($i = @$array; --$i; ) {
my $j = int rand ( $i+1 );
next if $i == $j;
@$array[$i, $j] = @$array[$j, $i];
}
}