#!/usr/bin/perl use strict; use warnings; while () { # only check between --- show switchname --- and ***** if ( /^-+ show switchname -+/ .. /^\*+/ ) { # only pick up the word between these two lines print "$1\n" if /(^\w+)/; } } __DATA__ show tech-support details -------------------- show switchname ------------------ CCC217_ANG_GREEN ****************************************************************** show tech-support details -------------------- show switchname ------------------ CCC218_ANG_GREEN ****************************************************************** show tech-support details -------------------- show switchname ------------------ CCC219_ANG_GREEN ****************************************************************** show tech-support details -------------------- show switchname ------------------ CCC220_ANG_GREEN ******************************************************************