foreach (@w) { print "working with $_... "; /^>>/ and do { print "error message\n"; next }; /^\s*([<>])\s*(\S+)/ and do { print "separated '$1' from '$2'\n"; next }; /^\s*\|/ and do { print "pipefront\n"; next }; /\|\s*$/ and do { print "pipeend\n"; next }; print "\n"; } __END__ working with >test.txt... separated '>' from 'test.txt' working with >test.txt... error message working with | test... pipefront working with test |... pipeend