... chomp; print $1, $/ if /^(?:.+)?\bsub\s+?(.+?){/; ## assumption still here if ( /^(.+)?\bsub\s+?(.+?)?{/s .. /^(.+)?}/s ) { ## anonymous sub included print $_, $/; } ...