use warnings; use strict; $| = 1; my @categories = ( 'V=aeiou', 'P=pbtdkg' ); while (1) { print "Text: "; my $text = ; chomp($text); last if ! $text; # Leere Eingabe beendet Schleife print "Regel: "; my $rule = ; chomp($rule); last if ! $rule; my ($search, $replace) = build_regex($rule); $text =~ s/$search/$replace/g; print "\nMuster: $search\n\nNach Ersetzung: $text\n\n"; } sub build_regex { # build_regex($rule); my ($to_replace, $replace_with, $pattern) = split('/', $_[0]); for my $category (@categories) { my ($type, $class) = split('=', $category); $pattern =~ s/$type/[$class]/g; } $pattern =~ s/(.+)_/(?<=$1)_/; $pattern =~ s/_(.+)/_(?=$1)/; $pattern =~ s/_/$to_replace/; # <--- edit return ($pattern, $replace_with); } __END__