in reply to File reading

davorg has correctly identified where the bug lies. 'if ( $first = 1 )' will assign 1 to $first and then submit the same as the value of the 'if' condition (1 being a true value). But there are some things which should become habitual, even when writing the first version:
#!/usr/bin/perl use strict; # avoid typos and unclear scoping... use warnings; # ...amongst other things # open fhand,file.txt; # this will now cause the # compilation error that it should # ...replacement further down... # declare and init your vars, including file handles my $file = 'file.txt' my $path = $ENV{ SOME_PATH } . '/' . $file; # or must cd? open my $fh, "<$path" or warn "$!: $file\n" and exit $?; # assume I/O can and will go wrong sometimes my $first = 0; while( <$fh> ){ # indent your nests for clarity # avoid falling thru from one case into the next if ( /First Name/ ) { $first = 1; # any other processing of First name line } elseif ( /Last Name/ ) { $first or die "Order is not correct\n"; # any other processing of Last name line } elsif ( 0 ) { # ...etc.... else { # default or 'all other' case if applicable } } close $fh; # specifically close filehandles

-M

Free your mind