#!/usr/bin/perl use strict; use warnings; my $var1 = "123x456x789xabc"; my $var2 = ""; my $vorkommen = 0; ($var2 = $var1) =~ s/^((?:.*?x){$vorkommen})[^x]*?(x.*)$/${1}PROBE$2/; print $var2;