in reply to nested if statement wont work

You can simplify that by using the Tie::File module:
#!/usr/bin/perl use warnings; use strict; use Tie::File; my $ffdb = 'ffdb.dat'; tie my @ffdbdata, 'Tie::File', $ffdb or die "Cannot open $ffdb: $!"; print "Enter ID \n"; my $ID = <STDIN>; chomp $ID; if ( $ID eq '' ) { die "Cant be empty!\n"; } foreach ( @ffdbdata ) { s!(?<=^$ID\|)(?:IN|OUT)$!@{[ /IN/ ? 'OUT' : 'IN' ]}! and last; } untie @ffdbdata; exit 0;