use strict; use warnings 'all'; my $str = do {local $/ = undef; }; my @Rec = $str =~ /-+\s+show switchname\s+-+[^\w]+(\w+)/ig; print "$_\n" for @Rec;