#!/usr/bin/perl -w use strict; my $last_test_file = "./last_test_file"; printf("before loop\n"); while (1) { if (open TEST_FILE, $last_test_file) { printf("after open\n"); /^\s*TEST_PATTERN\s+/ and last while ; printf("after match\n"); close(TEST_FILE); } else { die("ERROR: Unable to open $last_test_file for read, exiting...\n"); } } printf("after loop\n"); #### while () { /^\s*TEST_PATTERN\s+/ and last; }