sub whileIf { my( $arrayRef, $el, $offset, $distfile, $outfile ) = @_; if ($array2[$el + $offset] =~ /resid (\d+) and name (H\w+\d*).?\)/ and $array2[$el ] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; die "Can't open $distfil\ne" unless open DISTFILE, "$distfile"; WHILELOOP: while( defined( $line = ) ) { for my $offset2 ( 0 .. 5 ) { last WHILELOOP if $array2[$el + $offset] =~ /resid (\d+) and name (H\w+\d*).\n?\)/ and outputIf( $line, $atomid, $atomidmatch, $1, $2, $array2[$el], $outfile ) ; } } return 1; } return 0; }