in reply to Extracting text from a line

Or

#!usr/bin/perl use strict; use warnings; # 848903 my @strings = ("Supervisor UID: plbaerr4", "UID: dlsmith3", "Peon UID: jklmn2"); for my $string(@strings) { if ( $string !~ /^Supervisor \w+/ && $string =~ /UID: (\w+)/ ) { print "$1 \n"; } else { print "No match in $string \n"; } }

almut's reply handles the file-writing spec; this addresses ambiguity in OP's spec: is it the "Supervisor" UID that's verbotten or any UID preceded by a title?

Updated: preceding para dropped from cut and thus not pasted. Duh.