use strict; use warnings; use Data::Dumper; my $text = "foo##loop nase## foo  ##if nase-kz_gesetzt## foo\n##loop nase##foo ##if nase-kz_gesetzt##foo"; my @foo = split /(##.+?##)/, $text; my @bar = split /##(.+?)##/, $text; my @foobar = ($text =~ /##(.+?)##/g); chomp(@foo,@bar,@foobar); print Dumper(\@foo); print Dumper(\@bar); print Dumper(\@foobar);