#!/usr/bin/perl -w use strict; my $previous_line = ""; my $line = ""; open (DATA, "/export/home/webadm/scripts/backup_scripts/backup_data/1stnodupe"); while () { chop; $line = $_; if ($line =~ /^\S/) { # if line starts with Non-White Space Character if ($previous_line =~ /^\S/) { # if the previous line also # starts with Non-White Space Character # then do something with your successful finding like... print "$previous_line\n"; } else { # do something if not } } $previous_line = $line; }