#!/usr/bin/perl -w use strict; use diagnostics; print "Do some regex now, shall we?\n"; print "Give me a file. Full path, please.\n"; chomp(my $filepath = ); print "The filename is $filepath\n"; open FILE, "$filepath" or die "Couldn't open it. Error: $!\n"; my $count = 0; # Initialize the variable, just to be safe while () { if (/foo/) { $count++; print "$count so far.\n"; } } print "Program exiting\n";