in reply to RegEx Beginning of line or whitespace match
use strict; use diagnostics; my @line = ( 'some_for($var)', #don't match ' for($var)', #match 'for($var)', #match ); for ( @line ) { print /(^(\s+)?)for\(/gi ? "match\n" : "nomatch\n"; } [download]