#!/usr/bin/perl use strict; use warnings; my $file = '/path/to/file.txt'; my @array; { local $/ = "\n#"; open my $fh,'<',$file or die $!; while( my $article = <$fh> ){ my @info = $article =~ /^suchmuster1 (\d+) suchmuster2.*?suchmuster3([^\n]+).*suchmuster4(test)/i; push @array,join(";",@info); } } print $_,"\n" for @array;