#!/usr/bin/perl -w use strict; #1159495 my $input = 'abcd| a a7-'; my ( $item, @display, $display, $out, ); my @deSpaced = split / /, $input; for $item(@deSpaced) { if ($item =~ /(a).*\|/ ) { # match first part of $input? $out = '[' . $1 . ']'; push @display, $out; } if ( $item =~ /(^a$)/ ) { # match middle of $input? $out = '[' . $1 . ']'; push @display, $out; } elsif ( $item =~ /(a[0-9]{1}).+/ ) { # match last part of $input? $out = '[' . $1 . ']'; push @display, $out; } } foreach my $saved(@display) { print $saved . ' '; } =head EXECUTION: C:\ PMonks\1159495.pl [a] [a] [a7] C:\ =cut