how to let the perl script to run for each file

Hi,

I have more than 1 files in the directory. In bash, I can use

cd /work
 
for x in `ls`
do
:
: 
done

to run for each file in the directory.

How about in perl script?

filepath="ABC1"
open(FILE, $filepath) or die "$filepath cannot be opened.";
while(<FILE>) {
 :
 :
}
close(<file>)

because the open command just open the file ABC1 only. If I have ABC2, ABC3,ABC4 and ABC5 files.... how to let perl script also can run for the other files?

Thanks for you advise.

Probably easiest to understand:

my @files = </work/*>;
foreach my $file (@files) {
    open my $FH, '<', $file or die "Can't open file $file: $!";
    # do your magic here
    close $FH;
}

Don't forget your warnings, strictures, and diagnostics.