#!/usr/bin/perl use strict; use warnings; my $str= '$r->vor; $r->vor; $r->vor; $r->drehe_rechts; $r->vor; $r->vor; $r->drehe_links; $r->vor; $r->vor; $r->vor; $r->vor; $r->vor; drehe_um; $r->vor; '; $str =~ s!((?:\$r->vor;?\n?){2,})! my $anz = () = $1 =~ m/(\$r->vor;?\n?)/sg; my $string = "vor(".$anz.");\n"!esg; print $str;