use strict; use warnings; sub create_file ($$) {   my ($lines, $file) = @_;   open my $fh, '>', $file or die $!;   for (1..$lines) {      print $fh sprintf("%0".length($lines)."d", $_), " wort1 wort2 wort3\n";   }   close $fh; } sub search_in_file ($$$) {   my ($line, $file, $search) = @_;   open my $fh, '<', $file or die $!;   my $first_line = <$fh>;   my $length = length($first_line);   seek($fh, $length*(--$line), 0);   my $this_line = <$fh>;   return 1 if $this_line =~ /$search/;   return undef; } my $lines  = 100000; my $search = 'wort1'; my $line   = 50000; my $file   = './test.txt'; create_file($lines, $file); if (search_in_file($line, $file, $search)) {   print "HIT\n"; } else {   print "NO HIT\n"; }