in reply to Search for text from user input

I'm not quite sure if the code below is what you're looking for, but it works for what it seems that you want to do:
#!/usr/bin/perl use strict; use warnings; print "Please enter text for string search: "; my $search=<STDIN>; chomp $search; opendir(DIR, ".") or die "Cannot open dir ($!)\n"; while (my $file = readdir(DIR)) { print "$file\n" if ( $file =~ /$search\.jpg|$search\.jpeg/i ); } closedir(DIR); exit 0;
As others have said, it's a good idea to use warnings and use strict, always. This would be easy to modify to make it accept input on the directory as well. The i flag at the end of the regex ( /pattern/i ) makes it match case-insensitive. That way you do not need to specify JPEG, Jpeg, jpeg, and so on...