use strict; use warnings; use Tie::File; my $file_name = 'test.txt'; my @name; tie @name, 'Tie::File' ,$file_name; die "error!!!" unless defined (my $pid_1 = fork()); exit search_string(0,9999,"8888") unless ($pid_1); die "error!!!" unless defined (my $pid_2 = fork()); exit search_string(10000,19999,"18888") unless ($pid_2); die "error!!!" unless defined (my $pid_3 = fork()); exit search_string(20000,29999,"28888") unless ($pid_3); wait; wait; wait; untie @name; sub search_string { my ($from,$to,$string) = @_; for ($from .. $to) { print "the $_ th line of test.txt is $string\n" if $name[$_] =~ /^$string$/x; } } __test.txt__ 1 2 3 ... 29998 29999 30000