A B C D E F G #### B D E G #### blank line goes here!! B blank line goes here!! D E blank line goes here!! G #### #!/usr/bin/perl #Usage use strict; use warnings; my $filename1 = $ARGV[0]; my $filename2 = $ARGV[1]; open FILE, $filename1 or die $!; open FILE2, $filename2 or die $!; while() { while() { #Magic happens. Loop through 2 files in parallel, somehow making the 1st loop advance to the next line when it matches the text in the second loop's line. } }