Question: I'm reading a file and then running a for loop for each value. My script is stopping after executing the first value. The file\_detail.txt has multiple lines. But it is not proceeding to the next value. My script looks something like this --

```
    open (my $fh, "<", "$mycrdir/file_detail.txt" );
foreach(my $value = <$fh>) {
    chomp($value);
    if ($value eq "abc") {
        qx/"mkdir $mydir"/;
        func1($mycrnum,$mydir,$value,%envparams);
        func2($mycrnum,$mydir,$value,%envparams);
    }
    elsif($value eq "123") 
    {
        qx/"mkdir $mydir"/;
        func1($mycrnum,$mydir,$value,%envparams);
        func2($mycrnum,$mydir,$value,%envparams);
    }
}

```

Answer: 
Change your `foreach` to `while`.

`my $value = <$fh>` returns a single value, which is the first line of the file. `foreach` then receives that single value and loops over only that one value, after which the loop terminates without reading the next line from `$fh`.
Either use while loop as Dave mentioned or slurp the file in an array then loop over array using foreach. 

```
use IO::All;

my @lines = io($filename)->slurp;

foreach (@lines){
    #work on each line
}

```