use strict; use warnings; my @shell_rtn_val; print "Enter name of file to copy: "; my $file = ; # open STDIN and get input chomp $file; # remove the \n $file =~s /\\/\\\\/g; # Convert to Win32 Shell path sep $file =~s /\//\\\\/g; # Use Unix path's too :-) @shell_rtn_val = `copy $file $file."bak"`; foreach(@shell_rtn_val){ #Let's look for interesting stuff and process it # $_ is implicitly searched for in each if # just like you wrote: $_ =~ m/regex-pattern/ if ( /(\d) file\(s\) copied/ ){ my $num = $1;print "You copied $num files"; } if ( /cannot find/ ){ print "System can't find a file by that name"; } if ( /syntax/ ){ print "Bad syntax"; `copy /?`; } }