#!/usr/bin/perl use strict; use warnings; my $infile ='test.dat'; my $outfile='out.dat'; my $search ='[HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST2]'; my $outstr; { open(my $fh, '<', $infile) or die(qq'ERROR open "$infile" ($!)\n'); # Zeilenende auf "\n\n" setzen local $/="\n\n"; while(my $block=<$fh>) { if($block=~/\Q$search\E/) { $outstr=$block; last; } } close($fh); } die(qq'Key "$search" not found in $infile') unless($outstr); { open(my $fh, '>', $outfile) or die(qq'ERROR open "$outfile" ($!)\n'); print $fh $outstr; close($fh); }